Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
simonmilz opened this issue Sep 18, 2024 · 3 comments
Open

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

simonmilz opened this issue Sep 18, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@simonmilz
Copy link

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

@simonmilz simonmilz added the bug Something isn't working label Sep 18, 2024
@StanBarrows
Copy link
Contributor

StanBarrows commented Sep 19, 2024

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
Copy link
Author

simonmilz commented Sep 19, 2024

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

@StanBarrows
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants