Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| NlstCommand | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | namespace Apie\FtpServer\Commands; |
| 3 | |
| 4 | use Apie\ApieFileSystem\ApieFilesystem; |
| 5 | use Apie\ApieFileSystem\Virtual\VirtualFileInterface; |
| 6 | use Apie\ApieFileSystem\Virtual\VirtualFolderInterface; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | use Apie\FtpServer\FtpConstants; |
| 9 | use React\Socket\ConnectionInterface; |
| 10 | |
| 11 | class NlstCommand implements CommandInterface |
| 12 | { |
| 13 | public function run(ApieContext $apieContext, string $arg = ''): ApieContext |
| 14 | { |
| 15 | $conn = $apieContext->getContext(ConnectionInterface::class); |
| 16 | $filesystem = $apieContext->getContext(ApieFilesystem::class); |
| 17 | assert($filesystem instanceof ApieFilesystem); |
| 18 | $currentFolder = $arg ? $filesystem->visit($arg) : $apieContext->getContext(FtpConstants::CURRENT_FOLDER); |
| 19 | if ($currentFolder instanceof VirtualFolderInterface) { |
| 20 | $files = array_map( |
| 21 | function (VirtualFolderInterface|VirtualFileInterface $child) { |
| 22 | return $child->getName(); |
| 23 | }, |
| 24 | $currentFolder->getChildren()->toArray() |
| 25 | ); |
| 26 | $conn->write(implode("\r\n", $files) . "\r\n"); |
| 27 | $conn->write("226 NLST command successful.\r\n"); |
| 28 | } else { |
| 29 | $conn->write("450 Path is not a folder.\r\n"); |
| 30 | } |
| 31 | return $apieContext; |
| 32 | } |
| 33 | } |