Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FtpServerRunner | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| run | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\FtpServer; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\FtpServer\Commands\ListCommand; |
| 6 | use Apie\FtpServer\Commands\NlstCommand; |
| 7 | use Apie\FtpServer\Commands\PassCommand; |
| 8 | use Apie\FtpServer\Commands\PortCommand; |
| 9 | use Apie\FtpServer\Commands\PwdCommand; |
| 10 | use Apie\FtpServer\Commands\QuitCommand; |
| 11 | use Apie\FtpServer\Commands\RetrCommand; |
| 12 | use Apie\FtpServer\Commands\TypeCommand; |
| 13 | use Apie\FtpServer\Commands\UserCommand; |
| 14 | use Apie\FtpServer\Lists\CommandHashmap; |
| 15 | use React\Socket\ConnectionInterface; |
| 16 | |
| 17 | class FtpServerRunner |
| 18 | { |
| 19 | public function __construct( |
| 20 | private readonly CommandHashmap $commands |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public static function create(): self |
| 25 | { |
| 26 | return new self( |
| 27 | new CommandHashmap([ |
| 28 | 'USER' => new UserCommand(), |
| 29 | 'PASS' => new PassCommand(), |
| 30 | 'PWD' => new PwdCommand(), |
| 31 | 'LIST' => new ListCommand(), |
| 32 | 'RETR' => new RetrCommand(), |
| 33 | 'QUIT' => new QuitCommand(), |
| 34 | 'TYPE' => new TypeCommand(), |
| 35 | 'PORT' => new PortCommand(), |
| 36 | 'NLST' => new NlstCommand(), |
| 37 | ]) |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | public function run(ApieContext $apieContext, string $command, string $arguments = ''): ApieContext |
| 42 | { |
| 43 | if (!isset($this->commands[$command])) { |
| 44 | $apieContext->getContext(ConnectionInterface::class)->write("502 Command not implemented\r\n"); |
| 45 | error_log("Unknown command " . $command); |
| 46 | return $apieContext; |
| 47 | } |
| 48 | $commandExecutable = $this->commands[$command]; |
| 49 | return $commandExecutable->run($apieContext, $arguments); |
| 50 | } |
| 51 | } |