Пример #1
0
 public function testCountable()
 {
     // Verify that the interface Countable is properly
     // implemented.
     $mockJSON = array('count' => 5, 'bytes' => 128, 'name' => 'foo');
     $container = Container::newFromJSON($mockJSON, 'fake', 'fake');
     $this->assertEquals(5, count($container));
 }
Пример #2
0
 /**
  * Fetch a list of containers for this account.
  *
  * By default, this fetches the entire list of containers for the
  * given account. 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.
  *
  * @retval array
  * @return array
  *   An associative array of containers, where the key is the
  *   container's name and the value is an
  *   HPCloud::Storage::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);
     }
     $containers = $this->get($url);
     $containerList = array();
     foreach ($containers as $container) {
         $cname = $container['name'];
         $containerList[$cname] = Container::newFromJSON($container, $this->token(), $this->url());
         if (!empty($this->cdnContainers[$cname])) {
             $cdnList = $this->cdnContainers[$cname];
             $containerList[$cname]->useCDN($cdnList['url'], $cdnList['sslUrl']);
         }
     }
     return $containerList;
 }