Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
FtpServerRunner
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Apie\FtpServer;
3
4use Apie\Core\Context\ApieContext;
5use Apie\FtpServer\Commands\ListCommand;
6use Apie\FtpServer\Commands\NlstCommand;
7use Apie\FtpServer\Commands\PassCommand;
8use Apie\FtpServer\Commands\PortCommand;
9use Apie\FtpServer\Commands\PwdCommand;
10use Apie\FtpServer\Commands\QuitCommand;
11use Apie\FtpServer\Commands\RetrCommand;
12use Apie\FtpServer\Commands\TypeCommand;
13use Apie\FtpServer\Commands\UserCommand;
14use Apie\FtpServer\Lists\CommandHashmap;
15use React\Socket\ConnectionInterface;
16
17class 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}