Example #1
0
 /**
  * Return an array of Objects
  *
  * Return an array of Object instances in this Container.
  *
  * Example:
  * <code>
  * # ... authentication code excluded (see previous examples) ...
  * #
  * $images = $conn->get_container("my photos");
  *
  * # Grab the list of all storage objects
  * #
  * $all_objects = $images->get_objects();
  *
  * # Grab subsets of all storage objects
  * #
  * $first_ten = $images->get_objects(10);
  *
  * # Note the use of the previous result's last object name being
  * # used as the 'marker' parameter to fetch the next 10 objects
  * #
  * $next_ten = $images->list_objects(10, $first_ten[count($first_ten)-1]);
  *
  * # Grab images starting with "birthday_party" and default limit/marker
  * # to match all photos with that prefix
  * #
  * $prefixed = $images->get_objects(0, NULL, "birthday");
  *
  * # Assuming you have created the appropriate directory marker Objects,
  * # you can traverse your pseudo-hierarchical containers
  * # with the "path" argument.
  * #
  * $animals = $images->get_objects(0,NULL,NULL,"pictures/animals");
  * $dogs = $images->get_objects(0,NULL,NULL,"pictures/animals/dogs");
  * </code>
  *
  * @param int $limit <i>optional</i> only return $limit names
  * @param int $marker <i>optional</i> subset of names starting at $marker
  * @param string $prefix <i>optional</i> Objects whose names begin with $prefix
  * @param string $path <i>optional</i> only return results under "pathname"
  * @return array array of strings
  * @throws InvalidResponseException unexpected response
  */
 function get_objects($limit = 0, $marker = NULL, $prefix = NULL, $path = NULL, $delimiter = NULL)
 {
     list($status, $reason, $obj_array) = $this->cfs_http->get_objects($this->name, $limit, $marker, $prefix, $path, $delimiter);
     #if ($status == 401 && $this->_re_auth()) {
     #    return $this->get_objects($limit, $marker, $prefix, $path);
     #}
     if ($status < 200 || $status > 299) {
         throw new InvalidResponseException("Invalid response (" . $status . "): " . $this->cfs_http->get_error());
     }
     $objects = array();
     foreach ($obj_array as $obj) {
         if (!isset($obj['subdir'])) {
             $tmp = new UpdraftPlus_CF_Object($this, $obj["name"], False, False);
             $tmp->content_type = $obj["content_type"];
             $tmp->content_length = (double) $obj["bytes"];
             $tmp->set_etag($obj["hash"]);
             $tmp->last_modified = $obj["last_modified"];
             $objects[] = $tmp;
         }
     }
     return $objects;
 }