protected function handleResults(Model $result) { // Get the list of objects and record the last key $objects = $result->get('Contents') ?: array(); $numObjects = count($objects); $lastKey = $numObjects ? $objects[$numObjects - 1]['Key'] : false; if ($lastKey && !$result->hasKey($this->get('output_token'))) { $result->set($this->get('output_token'), $lastKey); } // Closure for getting the name of an object or prefix $getName = function ($object) { return isset($object['Key']) ? $object['Key'] : $object['Prefix']; }; // If common prefixes returned (i.e. a delimiter was set) and they need to be returned, there is more to do if ($this->get('return_prefixes') && $result->hasKey('CommonPrefixes')) { // Collect and format the prefixes to include with the objects $objects = array_merge($objects, $result->get('CommonPrefixes')); // Sort the objects and prefixes to maintain alphabetical order, but only if some of each were returned if ($this->get('sort_results') && $lastKey && $objects) { usort($objects, function ($object1, $object2) use($getName) { return strcmp($getName($object1), $getName($object2)); }); } } // If only the names are desired, iterate through the results and convert the arrays to the object/prefix names if ($this->get('names_only')) { $objects = array_map($getName, $objects); } return $objects; }
/** * {@inheritdoc} */ protected function handleResults(Model $result) { // Get the list of uploads $uploads = $result->get('Uploads') ?: array(); // If there are prefixes and we want them, merge them in if ($this->get('return_prefixes') && $result->hasKey('CommonPrefixes')) { $uploads = array_merge($uploads, $result->get('CommonPrefixes')); } return $uploads; }
/** * {@inheritdoc} */ protected function handleResults(Model $result) { // Get the list of object versions $versions = $result->get('Versions') ?: array(); $deleteMarkers = $result->get('DeleteMarkers') ?: array(); $versions = array_merge($versions, $deleteMarkers); // If there are prefixes and we want them, merge them in if ($this->get('return_prefixes') && $result->hasKey('CommonPrefixes')) { $versions = array_merge($versions, $result->get('CommonPrefixes')); } return $versions; }