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

How can i get one element on listContent? #1777

Open
ElUtku opened this issue Mar 23, 2024 · 0 comments
Open

How can i get one element on listContent? #1777

ElUtku opened this issue Mar 23, 2024 · 0 comments

Comments

@ElUtku
Copy link

ElUtku commented Mar 23, 2024

Question

Q A
Flysystem Version 3.23.0
Adapter Name All
Adapter version -

Hello,
is there any way to get the json of a single item?
example:

League\Flysystem\DirectoryAttributes {#594 ▼
  -type: "dir"
  -path: "Test\Test2"
  -visibility: "private"
  -lastModified: 1702292652
  -extraMetadata: array:3 [▼
    "id" => ""
    "virtual_path" => ""
    "display_path" => "Test2"
  ]
}

Currently I have to get all elements of a path and check if the original path matches the path of the current $item. This is inefficient and I don't know if there is a way to get the file or directory directly through a listContent($path).

$contents=$filesystem->listContents(dirname($ruta))->toArray();

foreach ($contents as $item) {
       if ($item['path']==$ruta || str_replace('\\', '/',$item['path']) == $ruta) {  // /a/b/c.txt == /a/b/c.txt
             
            if ($item instanceof FileAttributes) {
                        return new FileAttributes($ruta,$item->fileSize(),$item->visibility(),$item->lastModified(),$item->mimeType(),$item->extraMetadata());
            } elseif ($item instanceof \League\Flysystem\DirectoryAttributes) {
                        return new DirectoryAttributes($ruta,$item->visibility(),$item->lastModified(),$item->extraMetadata());
            }

       }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant