/** * {@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; }
/** * {@inheritdoc} */ protected function handleResults(Model $result) { // Get the results $buckets = $result->get('Buckets') ?: array(); // If only the names_only set, change arrays to a string if ($this->get('names_only')) { foreach ($buckets as &$bucket) { $bucket = $bucket['Name']; } } return $buckets; }
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; }
/** * Extracts the value from the result using Collection::getPath. Also adds some additional logic for keys that need * to access n-1 indexes (e.g., ImportExport, Kinesis). The n-1 logic only works for the known cases. We will switch * to a jmespath implementation in the future to cover all cases * * @param Model $result * @param string $key * * @return mixed|null */ protected function getValueFromResult(Model $result, $key) { // Special handling for keys that need to access n-1 indexes if (strpos($key, '#') !== false) { $keyParts = explode('#', $key, 2); $items = $result->getPath(trim($keyParts[0], '/')); if ($items && is_array($items)) { $index = count($items) - 1; $key = strtr($key, array('#' => $index)); } } // Get the value return $result->getPath($key); }
/** * Check to see if the path of the output key is satisfied by the value * * @param Model $model Result model * @param string $key Key to check * @param string $checkValue Compare the key to the value * @param bool $all Set to true to ensure all value match or false to only match one * * @return bool */ protected function checkPath(Model $model, $key = null, $checkValue = array(), $all = true) { // If no key is set, then just assume true because the request succeeded if (!$key) { return true; } if (!($result = $model->getPath($key))) { return false; } $total = $matches = 0; foreach ((array) $result as $value) { $total++; foreach ((array) $checkValue as $check) { if ($value == $check) { $matches++; break; } } } // When matching all values, ensure that the match count matches the total count if ($all && $total != $matches) { return false; } return $matches > 0; }