| 1 | <?php |
||
| 6 | abstract class BaseTransport implements TransportInterface |
||
| 7 | { |
||
| 8 | /** @var resource|null|false */ |
||
| 9 | protected $target; |
||
| 10 | protected string $schema = ''; |
||
|
|
|||
| 11 | protected WriterInterface $writer; |
||
| 12 | |||
| 13 | public function __construct(WriterInterface $writer = null) |
||
| 14 | { |
||
| 15 | 16 | $this->writer = $writer ?? new Writer; |
|
| 16 | } |
||
| 17 | 16 | ||
| 18 | 16 | public function getWriter(): WriterInterface |
|
| 19 | { |
||
| 20 | 4 | return $this->writer; |
|
| 21 | } |
||
| 22 | 4 | ||
| 23 | public function write(string $buffer, int $length = null): int |
||
| 24 | { |
||
| 25 | return $this->writer->write($this->target, $buffer, $length); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function isConnected(): bool |
||
| 29 | { |
||
| 30 | return is_resource($this->target) && !feof($this->target); |
||
| 31 | 16 | } |
|
| 32 | |||
| 33 | 16 | public function close(): void |
|
| 34 | { |
||
| 35 | $this->target && fclose($this->target); |
||
| 36 | 12 | $this->target = null; |
|
| 37 | } |
||
| 38 | } |
||
| 39 |