codebar-ag / laravel-flysystem-cloudinary

Cloudinary Flysystem integration with Laravel.
https://www.cloudinary.com
MIT License
8 stars 5 forks source link

[Bug]: listContents returns array instead of iterable #64

Open simonmilz opened 3 days ago

simonmilz commented 3 days ago

What happened?

I run into this issue:

Illuminate\Filesystem\FilesystemAdapter::Illuminate\Filesystem\{closure}(): Argument #1 ($attributes) must be of type League\Flysystem\StorageAttributes, array given

which kinda make sense as the listContents method should return iterable instead of array. The FilesystemAdapter.php in Laravel expects an array of StorageAttributes:

    public function files($directory = null, $recursive = false)
    {
        return $this->driver->listContents($directory ?? '', $recursive)
            ->filter(function (StorageAttributes $attributes) {
                return $attributes->isFile();
            })
            ->sortByPath()
            ->map(function (StorageAttributes $attributes) {
                return $attributes->path();
            })
            ->toArray();
    }

Package Version

3.1

PHP Version

8.3

Laravel Version

10

Which operating systems does with happen with?

No response

StanBarrows commented 2 days ago

Hi @simonmilz

Can you give us a little more information about the issue? Where does this happen? I've quickly checked the Core Library "vendor/laravel/src/Filesystem/FilesystemAdapter" and this is returning an array as well.

CleanShot 2024-09-19 at 14 16 38@2x

simonmilz commented 2 days ago

@StanBarrows you need to check the listContents method which is being called.

StanBarrows commented 1 day ago

Hey @simonmilz,

Could you please provide an example or some code to help us reproduce the error? I noticed that the FileSystemAdapter is returning a DirectlyListing object, while we are returning an array. However, in the current implementations where we use the package, it seems to be working with the array as well.

public function listContents(string $location, bool $deep = self::LIST_SHALLOW): DirectoryListing;

Also happy for a PR if you know the fix already.

Best regards