get('Contents') ?: array(); $numObjects = count($objects); $lastKey = $numObjects ? $objects[$numObjects - 1]['Key'] : false; if ($lastKey && !$result->hasKey($this->get('token_key'))) { $result->set($this->get('token_key'), $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; } }