Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ListCommand | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| run | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
6 | |||
| 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 Apie\FtpServer\Transfers\TransferInterface; |
| 10 | use React\Socket\ConnectionInterface; |
| 11 | |
| 12 | class ListCommand implements CommandInterface |
| 13 | { |
| 14 | public function run(ApieContext $apieContext, string $arg = ''): ApieContext |
| 15 | { |
| 16 | $conn = $apieContext->getContext(ConnectionInterface::class); |
| 17 | $filesystem = $apieContext->getContext(ApieFilesystem::class); |
| 18 | assert($filesystem instanceof ApieFilesystem); |
| 19 | $currentFolder = $arg ? $filesystem->visit($arg) : $apieContext->getContext(FtpConstants::CURRENT_FOLDER); |
| 20 | $conn->write("150 Here comes the directory listing\r\n"); |
| 21 | $transfer = $apieContext->getContext(TransferInterface::class); |
| 22 | foreach ($currentFolder->getChildren() as $child) { |
| 23 | $size = ''; |
| 24 | if ($child instanceof VirtualFileInterface) { |
| 25 | $size = $child->getSize() ?? '0'; |
| 26 | } |
| 27 | $transfer->send( |
| 28 | ($child instanceof VirtualFolderInterface ? 'd' : '-') |
| 29 | . "rw-r--r-- 1 user group " |
| 30 | . $size |
| 31 | . ($child instanceof VirtualFolderInterface ? " Jan 1 " : ' ') . $child->getName() . "\r\n" |
| 32 | ); |
| 33 | } |
| 34 | $transfer->end(); |
| 35 | $conn->write("212 Directory send OK\r\n"); |
| 36 | return $apieContext; |
| 37 | } |
| 38 | } |