Skip to content

Commit dc1356b

Browse files
Merge pull request #72 from brandon14/fix/list-contents
fix/list-contents: Fix listContents to return iterable FileAttributes
2 parents 7ff75be + 8914821 commit dc1356b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/CloudinaryAdapter.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function visibility(string $path): FileAttributes
296296
*
297297
* @param string $directory
298298
* @param bool $hasRecursive
299-
* @return array
299+
* @return iterable<\League\Flysystem\StorageAttributes>
300300
*/
301301
public function listContents($directory = '', $hasRecursive = false): iterable
302302
{
@@ -318,11 +318,30 @@ public function listContents($directory = '', $hasRecursive = false): iterable
318318

319319
// parse resourses
320320
foreach ($resources as $i => $resource) {
321-
$resources[$i] = $this->prepareResourceMetadata($resource);
321+
$resources[$i] = $this->prepareFileAttributes($this->prepareResourceMetadata($resource));
322322
}
323323
return $resources;
324324
}
325325

326+
/**
327+
* Transform array of resource metadata into a {@link \League\Flysystem\FileAttributes} instance.
328+
*
329+
* @param array $metadata
330+
*
331+
* @return \League\Flysystem\FileAttributes
332+
*/
333+
protected function prepareFileAttributes(array $metadata): FileAttributes
334+
{
335+
return new FileAttributes(
336+
$metadata['path'],
337+
$metadata['size'],
338+
null,
339+
$metadata['timestamp'],
340+
$metadata['mimetype'],
341+
$metadata
342+
);
343+
}
344+
326345
/**
327346
* Prepare apropriate metadata for resource metadata given from cloudinary.
328347
* @param array $resource

0 commit comments

Comments
 (0)