Ejemplo n.º 1
0
 public function testCountable()
 {
     // Verify that the interface Countable is properly implemented.
     $mockJSON = ['count' => 5, 'bytes' => 128, 'name' => 'foo'];
     $container = Container::newFromJSON($mockJSON, 'fake', 'fake');
     $this->assertCount(5, $container);
 }
Ejemplo n.º 2
0
 /**
  * Fetch a list of containers for this user.
  *
  * By default, this fetches the entire list of containers for the
  * given user. If you have more than 10,000 containers (who
  * wouldn't?), you will need to use $marker for paging.
  *
  * If you want more controlled paging, you can use $limit to indicate
  * the number of containers returned per page, and $marker to indicate
  * the last container retrieved.
  *
  * Containers are ordered. That is, they will always come back in the
  * same order. For that reason, the pager takes $marker (the name of
  * the last container) as a paging parameter, rather than an offset
  * number.
  *
  * @todo For some reason, ACL information does not seem to be returned
  *   in the JSON data. Need to determine how to get that. As a
  *   stop-gap, when a container object returned from here has its ACL
  *   requested, it makes an additional round-trip to the server to
  *   fetch that data.
  *
  * @param int    $limit  The maximum number to return at a time. The default is
  *                       -- brace yourself -- 10,000 (as determined by OpenStack. Implementations
  *                       may vary).
  * @param string $marker The name of the last object seen. Used when paging.
  *
  * @return array An associative array of containers, where the key is the
  *               container's name and the value is an \OpenStack\ObjectStore\v1\ObjectStorage\Container
  *               object. Results are ordered in server order (the order that the remote
  *               host puts them in).
  */
 public function containers($limit = 0, $marker = null)
 {
     $url = $this->url() . '?format=json';
     if ($limit > 0) {
         $url .= sprintf('&limit=%d', $limit);
     }
     if (!empty($marker)) {
         $url .= sprintf('&marker=%d', $marker);
     }
     $headers = ['X-Auth-Token' => $this->token];
     $response = $this->client->get($url, ['headers' => $headers]);
     $containers = $response->json();
     $containerList = [];
     foreach ($containers as $container) {
         $cname = $container['name'];
         $containerList[$cname] = Container::newFromJSON($container, $this->token(), $this->url(), $this->client);
     }
     return $containerList;
 }