| 1 | <?php | ||
| 7 | abstract class CallbackStream | ||
| 8 | { | ||
| 9 | protected $stream; | ||
| 10 | |||
| 11 | private $onNewFrameCallables = []; | ||
| 12 | |||
| 13 | 8 | public function __construct(StreamInterface $stream) | |
| 17 | |||
| 18 | /** | ||
| 19 | * Called when there is a new frame from the stream | ||
| 20 | * | ||
| 21 | * @param callable $onNewFrame | ||
| 22 | */ | ||
| 23 | 8 | public function onFrame(callable $onNewFrame) | |
| 27 | |||
| 28 | /** | ||
| 29 | * Read a frame in the stream | ||
| 30 | * | ||
| 31 | * @return mixed | ||
| 32 | */ | ||
| 33 | abstract protected function readFrame(); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Wait for stream to finish and call callables if defined | ||
| 37 | */ | ||
| 38 | 8 | public function wait() | |
| 54 | |||
| 55 | public function closeAndRead() | ||
| 60 | } | ||
| 61 |