Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
RetrCommand
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
3.00
0.00% covered (danger)
0.00%
0 / 1
 run
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
3.00
1<?php
2namespace Apie\FtpServer\Commands;
3
4use Apie\ApieFileSystem\Virtual\VirtualFolderInterface;
5use Apie\Core\Context\ApieContext;
6use Apie\Core\ValueObjects\Utils;
7use Apie\FtpServer\FtpConstants;
8use Apie\FtpServer\Transfers\TransferInterface;
9use React\Socket\ConnectionInterface;
10
11class RetrCommand implements CommandInterface
12{
13    public function run(ApieContext $apieContext, string $arg = ''): ApieContext
14    {
15        $conn = $apieContext->getContext(ConnectionInterface::class);
16        if (!$arg) {
17            $conn->write("501 Missing filename\r\n");
18        } else {
19            $folder = $apieContext->getContext(FtpConstants::CURRENT_FOLDER);
20            assert($folder instanceof VirtualFolderInterface);
21            $file = $folder->getChild($arg);
22            $transfer = $apieContext->getContext(TransferInterface::class);
23            assert($transfer instanceof TransferInterface);
24            if ($file === null) {
25                $conn->write("550 File not found\r\n");
26            } else {
27                $conn->write("150 Opening data connection\r\n");
28                $transfer->send(Utils::toString($file->getContents()));
29                $conn->write("226 Transfer complete\r\n");
30            }
31        }
32        return $apieContext;
33    }
34}