listContents and filter: Attempted to call an undefined method named "filter" of class "Generator".
ziggurad opened this issue · comments
How filter listing?
Q | A |
---|---|
Flysystem Version | 3.23.0 |
Adapter Name | FTP |
Adapter version | 3.22.0 |
Hello,
I need some help. I would get a list of only files from the selected folder. I found an example from https://flysystem.thephpleague.com/docs/usage/directory-listings/
$allFiles = $filesystem->listContents('/some/path')
->filter(fn (StorageAttributes $attributes) => $attributes->isFile());
Unfortunately, in my case the code doesn't work, can anyone help?
$this->client = new FtpAdapter(
FtpConnectionOptions::fromArray([
'host' => $FTPConfiguration->host,
'root' => '/',
'username' => $FTPConfiguration->username,
'password' => $FTPConfiguration->password,
'port' => $FTPConfiguration->port,
'ssl' => false,
'timeout' => 90,
'utf8' => false,
'passive' => true,
'transferMode' => FTP_BINARY,
'systemType' => null, // 'windows' or 'unix'
'ignorePassiveAddress' => null, // true or false
'timestampsOnUnixListingsEnabled' => false, // true or false
'recurseManually' => true // true
])
);
return $this->client->listContents($folderToImport, false)
->filter(fn (StorageAttributes $attributes) => $attributes->isFile());
And get: " Attempted to call an undefined method named "filter" of class "Generator"."
@ziggurad when you say "doesn't work" what does that mean? What did you expect and what was the response? In addition, what kind of FTP server are you talking to?
Ah I see your problem now. You're calling this on the adapter by should be calling it on the filesystem instance. Never interact with the adapter directly. Always go through the filesystem instance.
@frankdejonge of course you are right, thank you for your help!