Skip to content

Commit

Permalink
added getObjectsAndPrefixesByBucket() to Amazon S3 class. see issue Z…
Browse files Browse the repository at this point in the history
…F-11401 for ZF1 change.
  • Loading branch information
jonnott committed Nov 21, 2011
1 parent 0a759f4 commit cf4c53c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions library/Zend/Service/Amazon/S3/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,52 @@ public function getObjectsByBucket($bucket, $params = array())

return $objects;
}

/**
* List the objects and common prefixes in a bucket.
*
* Provides the list of object keys and common prefixes that are contained in the bucket. Valid params include the following.
* prefix - Limits the response to keys which begin with the indicated prefix. You can use prefixes to separate a bucket into different sets of keys in a way similar to how a file system uses folders.
* marker - Indicates where in the bucket to begin listing. The list will only include keys that occur lexicographically after marker. This is convenient for pagination: To get the next page of results use the last key of the current page as the marker.
* max-keys - The maximum number of keys you'd like to see in the response body. The server might return fewer than this many keys, but will not return more.
* delimiter - Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response.
*
* @param string $bucket
* @param array $params S3 GET Bucket Paramater
* @return array|false
*/
public function getObjectsAndPrefixesByBucket($bucket, $params = array())
{
$response = $this->_makeRequest('GET', $bucket, $params);

if ($response->getStatus() != 200) {
return false;
}

$xml = new \SimpleXMLElement($response->getBody());

$objects = array();
if (isset($xml->Contents)) {
foreach ($xml->Contents as $contents) {
foreach ($contents->Key as $object) {
$objects[] = (string)$object;
}
}
}
$prefixes = array();
if (isset($xml->CommonPrefixes)) {
foreach ($xml->CommonPrefixes as $prefix) {
foreach ($prefix->Prefix as $object) {
$prefixes[] = (string)$object;
}
}
}

return array(
'objects' => $objects,
'prefixes' => $prefixes
);
}

/**
* Make sure the object name is valid
Expand Down

0 comments on commit cf4c53c

Please sign in to comment.