Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PortTransfer | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| send | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| end | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\FtpServer\Transfers; |
| 3 | |
| 4 | use React\Promise\PromiseInterface; |
| 5 | use React\Socket\ConnectionInterface; |
| 6 | use React\Socket\Connector; |
| 7 | |
| 8 | class PortTransfer implements TransferInterface |
| 9 | { |
| 10 | private Connector $connector; |
| 11 | |
| 12 | private PromiseInterface $connectComplete; |
| 13 | |
| 14 | public function __construct( |
| 15 | private readonly string $ip, |
| 16 | private readonly int $port |
| 17 | ) { |
| 18 | $this->connector = new Connector(); |
| 19 | } |
| 20 | |
| 21 | public function send(string $data, ?callable $onRejected = null): void |
| 22 | { |
| 23 | if (!isset($this->connectComplete)) { |
| 24 | $this->connectComplete = $this->connector->connect($this->ip . ':' . $this->port); |
| 25 | } |
| 26 | $this->connectComplete->then( |
| 27 | function (ConnectionInterface $connection) use ($data) { |
| 28 | $connection->write($data); |
| 29 | }, |
| 30 | $onRejected |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | public function end(): void |
| 35 | { |
| 36 | if (!isset($this->connectComplete)) { |
| 37 | $this->connectComplete = $this->connector->connect($this->ip . ':' . $this->port); |
| 38 | } |
| 39 | $this->connectComplete->then( |
| 40 | function (ConnectionInterface $connection) { |
| 41 | $connection->end(); |
| 42 | unset($this->connectComplete); |
| 43 | } |
| 44 | ); |
| 45 | } |
| 46 | } |