Exemplo n.º 1
0
 /**
  * Construct a new Container.
  *
  * Typically a container should be created by ObjectStorage::createContainer().
  * Get existing containers with ObjectStorage::container() or
  * ObjectStorage::containers(). Using the constructor directly has some
  * side effects of which you should be aware.
  *
  * Simply creating a container does not save the container remotely.
  *
  * Also, this does no checking of the underlying container. That is, simply
  * constructing a Container in no way guarantees that such a container exists
  * on the origin object store.
  *
  * The constructor involves a selective lazy loading. If a new container is created,
  * and one of its accessors is called before the accessed values are initialized, then
  * this will make a network round-trip to get the container from the remote server.
  *
  * Containers loaded from ObjectStorage::container() or Container::newFromRemote()
  * will have all of the necessary values set, and thus will not require an extra network
  * transaction to fetch properties.
  *
  * The practical result of this:
  *
  * - If you are creating a new container, it is best to do so with
  *   ObjectStorage::createContainer().
  * - If you are manipulating an existing container, it is best to load the
  *   container with ObjectStorage::container().
  * - If you are simply using the container to fetch resources from the
  *   container, you may wish to use `new Container($name, $url, $token)`
  *   and then load objects from that container. Note, however, that
  *   manipulating the container directly will likely involve an extra HTTP
  *   transaction to load the container data.
  * - When in doubt, use the ObjectStorage methods. That is always the safer
  *   option.
  *
  * @param string $name  The name.
  * @param string $url   The full URL to the container.
  * @param string $token The auth token.
  * @param \OpenStack\Common\Transport\ClientInterface $client A HTTP transport client.
  */
 public function __construct($name, $url = null, $token = null, ClientInterface $client = null)
 {
     $this->name = $name;
     $this->url = $url;
     $this->token = $token;
     // Guzzle is the default client to use.
     if (is_null($client)) {
         $this->client = GuzzleAdapter::create();
     } else {
         $this->client = $client;
     }
 }
Exemplo n.º 2
0
 /**
  * Build a new IdentityService object.
  *
  * Each object is bound to a particular identity services endpoint.
  *
  * For the URL, you are advised to use the version without a
  * version number at the end, e.g. http://cs.example.com/ rather
  * than http://cs.example.com/v2.0. The version number must be
  * controlled by the library.
  *
  * If a version is included in the URI, the library will attempt to use
  * that URI.
  *
  *     <?php
  *     $cs = new \OpenStack\Identity\v2\IdentityService('http://example.com');
  *     $token = $cs->authenticateAsUser($username, $password);
  *     ?>
  *
  * @param string $url An URL pointing to the Identity Service endpoint.
  *                    Note that you do not need the version identifier in the URL, as version
  *                    information is sent in the HTTP headers rather than in the URL. The URL
  *                    should always be to an SSL/TLS encrypted endpoint.
  *
  * @param \OpenStack\Common\Transport\ClientInterface $client An optional HTTP client to use when making the requests.
  */
 public function __construct($url, ClientInterface $client = null)
 {
     $parts = parse_url($url);
     if (!empty($parts['path'])) {
         $this->endpoint = rtrim($url, '/');
     } else {
         $this->endpoint = rtrim($url, '/') . '/v' . self::API_VERSION;
     }
     // Guzzle is the default client to use.
     if (is_null($client)) {
         $this->client = GuzzleAdapter::create();
     } else {
         $this->client = $client;
     }
 }
Exemplo n.º 3
0
 /**
  * Retrieve the HTTP Transport Client
  *
  * @return \OpenStack\Common\Transport\ClientInterface A transport client.
  */
 public static function getTransportClient()
 {
     if (is_null(self::$httpClient)) {
         $options = [];
         if (isset(self::$settings['transport.proxy'])) {
             $options['proxy'] = self::$settings['transport.proxy'];
         }
         if (isset(self::$settings['transport.debug'])) {
             $options['debug'] = self::$settings['transport.debug'];
         }
         if (isset(self::$settings['transport.ssl.verify'])) {
             $options['ssl_verify'] = self::$settings['transport.ssl.verify'];
         }
         if (isset(self::$settings['transport.timeout'])) {
             $options['timeout'] = self::$settings['transport.timeout'];
         }
         self::$httpClient = GuzzleAdapter::create(['defaults' => $options]);
     }
     return self::$httpClient;
 }
 public function testFactoryMethod()
 {
     $this->assertInstanceOf('OpenStack\\Common\\Transport\\Guzzle\\GuzzleAdapter', GuzzleAdapter::create());
 }
Exemplo n.º 5
0
 /**
  * Create a new RemoteObject from HTTP headers.
  *
  * This is used to create objects from GET and HEAD requests, which
  * return all of the metadata inside of the headers.
  *
  * @param string $name    The name of the object.
  * @param array  $headers An associative array of HTTP headers in the exact
  *                        format documented by OpenStack's API docs.
  * @param string $token   The current auth token (used for issuing subsequent
  *                        requests).
  * @param string $url     The URL to the object in the object storage. Used for
  *                        issuing subsequent requests.
  *
  * @return \OpenStack\ObjectStore\v1\Resource\RemoteObject A new RemoteObject.
  */
 public static function newFromHeaders($name, $headers, $token, $url, ClientInterface $client = null)
 {
     $object = new RemoteObject($name);
     //$object->allHeaders = $headers;
     $object->setHeaders($headers);
     //throw new \Exception(print_r($headers, true));
     // Fix inconsistant header.
     if (isset($headers['ETag'])) {
         $headers['Etag'] = $headers['ETag'];
     }
     $object->setContentType($headers['Content-Type']);
     $object->contentLength = empty($headers['Content-Length']) ? 0 : (int) $headers['Content-Length'];
     $object->etag = (string) $headers['Etag'];
     // ETag is now Etag.
     $object->lastModified = strtotime($headers['Last-Modified']);
     // Set the metadata, too.
     $object->setMetadata(Container::extractHeaderAttributes($headers));
     // If content encoding and disposition exist, set them on the
     // object.
     if (!empty($headers['Content-Disposition'])) {
         $object->setDisposition($headers['Content-Disposition']);
     }
     if (!empty($headers['Content-Encoding'])) {
         $object->setEncoding($headers['Content-Encoding']);
     }
     $object->token = $token;
     $object->url = $url;
     if (is_null($client)) {
         $client = GuzzleAdapter::create();
     }
     $object->setClient($client);
     return $object;
 }