Exemplo n.º 1
0
 /**
  * Factory method which allows for easy service creation
  *
  * @param  ClientInterface $client
  * @return self
  */
 public static function factory(ClientInterface $client)
 {
     $identity = new self();
     if (($client instanceof Base || $client instanceof OpenStack) && $client->hasLogger()) {
         $identity->setLogger($client->getLogger());
     }
     $identity->setClient($client);
     $identity->setEndpoint(clone $client->getAuthUrl());
     return $identity;
 }
Exemplo n.º 2
0
 /**
  * Factory method which allows for easy service creation
  *
  * @param  ClientInterface $client
  * @return self
  */
 public static function factory(\Guzzle\Http\ClientInterface $client)
 {
     $tempAuth = new self();
     if (($client instanceof \OpenCloud\Common\Base || $client instanceof \OpenCloud\OpenStack) && $client->hasLogger()) {
         $tempAuth->setLogger($client->getLogger());
     }
     $tempAuth->setClient($client);
     $tempAuth->setEndpoint(clone $client->getAuthUrl());
     return $tempAuth;
 }
Exemplo n.º 3
0
 /**
  * Creates a service object, based off the specified client.
  *
  * The service's URL is defined in the client's serviceCatalog; it
  * uses the $type, $name, $region, and $urlType to find the proper endpoint
  * and set it. If it cannot find a URL in the service catalog that matches
  * the criteria, then an exception is thrown.
  *
  * @param Client $client  Client object
  * @param string $type    Service type (e.g. 'compute')
  * @param string $name    Service name (e.g. 'cloudServersOpenStack')
  * @param string $region  Service region (e.g. 'DFW', 'ORD', 'IAD', 'LON', 'SYD' or 'HKG')
  * @param string $urlType Either 'publicURL' or 'internalURL'
  */
 public function __construct(ClientInterface $client, $type = null, $name = null, $region = null, $urlType = null)
 {
     if (($client instanceof Base || $client instanceof OpenStack) && $client->hasLogger()) {
         $this->setLogger($client->getLogger());
     }
     $this->setClient($client);
     $this->name = $name ?: static::DEFAULT_NAME;
     $this->region = $region;
     $this->region = $region;
     if ($this->regionless !== true && !$this->region) {
         throw new Exceptions\ServiceException(sprintf('The %s service must have a region set. You can either pass in a region string as an argument param, or' . ' set a default region for your user account by executing User::setDefaultRegion and ::update().', $this->name));
     }
     $this->type = $type ?: static::DEFAULT_TYPE;
     $this->urlType = $urlType ?: static::DEFAULT_URL_TYPE;
     $this->setEndpoint($this->findEndpoint());
     $this->client->setBaseUrl($this->getBaseUrl());
     if ($this instanceof EventSubscriberInterface) {
         $this->client->getEventDispatcher()->addSubscriber($this);
     }
 }