Skip to content

Instantly share code, notes, and snippets.

@jamiehannaford
Last active January 4, 2016 16:49
Show Gist options
  • Save jamiehannaford/8650053 to your computer and use it in GitHub Desktop.
Save jamiehannaford/8650053 to your computer and use it in GitHub Desktop.
override service class for HP services
use Guzzle\Http\ClientInterface;
use OpenCloud\Common\Service\CatalogService;
class HpService extends CatalogService
{
public function __construct(ClientInterface $client, $type = null, $region = null, $urlType = null)
{
$this->setClient($client);
$this->region = $region;
$this->type = $type;
$this->urlType = $urlType;
$this->setEndpoint($this->findHpEndpoint());
$this->client->setBaseUrl($this->getBaseUrl());
if ($this instanceof EventSubscriberInterface) {
$this->client->getEventDispatcher()->addSubscriber($this);
}
}
protected function findHpEndpoint()
{
if (!$this->getClient()->getCatalog()) {
$this->getClient()->authenticate();
}
$catalog = $this->getClient()->getCatalog();
foreach ($catalog->getItems() as $service) {
if ($service->hasType($this->type)) {
return Endpoint::factory($service->getEndpointFromRegion($this->region));
}
}
throw new \RuntimeException(sprintf(
'No endpoints for service type [%s], name [%s], region [%s] and urlType [%s]',
$this->type,
$this->name,
$this->region,
$this->urlType
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment