Google\Cloud\Storage\Bucket::objects PHP Method

objects() public method

Example: Get all objects beginning with the prefix 'photo' $objects = $bucket->objects([ 'prefix' => 'photo', 'fields' => 'items/name,nextPageToken' ]); foreach ($objects as $object) { echo $object->name() . PHP_EOL; }
See also: https://cloud.google.com/storage/docs/json_api/v1/objects/list Objects list API documentation.
public objects ( array $options = [] ) : Generator
$options array [optional] { Configuration options. @type string $delimiter Returns results in a directory-like mode. Results will contain only objects whose names, aside from the prefix, do not contain delimiter. Objects whose names, aside from the prefix, contain delimiter will have their name, truncated after the delimiter, returned in prefixes. Duplicate prefixes are omitted. @type integer $maxResults Maximum number of results to return per request. Defaults to `1000`. @type string $prefix Filter results with this prefix. @type string $projection Determines which properties to return. May be either 'full' or 'noAcl'. @type bool $versions If true, lists all versions of an object as distinct results. The default is false. @type string $fields Selector which will cause the response to only return the specified fields. }
return Generator
    public function objects(array $options = [])
    {
        $options['pageToken'] = null;
        $includeVersions = isset($options['versions']) ? $options['versions'] : false;
        do {
            $response = $this->connection->listObjects($options + $this->identity);
            if (!array_key_exists('items', $response)) {
                break;
            }
            foreach ($response['items'] as $object) {
                $generation = $includeVersions ? $object['generation'] : null;
                (yield new StorageObject($this->connection, $object['name'], $this->identity['bucket'], $generation, $object));
            }
            $options['pageToken'] = isset($response['nextPageToken']) ? $response['nextPageToken'] : null;
        } while ($options['pageToken']);
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function listContents($directory = '', $recursive = false)
 {
     $directory = $this->applyPathPrefix($directory);
     $objects = $this->bucket->objects(['prefix' => $directory]);
     $normalised = [];
     foreach ($objects as $object) {
         $normalised[] = $this->normaliseObject($object);
     }
     return Util::emulateDirectories($normalised);
 }
All Usage Examples Of Google\Cloud\Storage\Bucket::objects