1 | <?php |
||
7 | class DockerRawStream |
||
8 | { |
||
9 | const HEADER = 'application/vnd.docker.raw-stream'; |
||
10 | |||
11 | /** @var StreamInterface Stream for the response */ |
||
12 | protected $stream; |
||
13 | |||
14 | /** @var callable[] A list of callable to call when there is a stdin output */ |
||
15 | protected $onStdinCallables = []; |
||
16 | |||
17 | /** @var callable[] A list of callable to call when there is a stdout output */ |
||
18 | protected $onStdoutCallables = []; |
||
19 | |||
20 | /** @var callable[] A list of callable to call when there is a stderr output */ |
||
21 | protected $onStderrCallables = []; |
||
22 | |||
23 | 2 | public function __construct(StreamInterface $stream) |
|
27 | |||
28 | /** |
||
29 | * Add a callable to read stdin |
||
30 | * |
||
31 | * @param callable $callback |
||
32 | */ |
||
33 | public function onStdin(callable $callback) |
||
37 | |||
38 | /** |
||
39 | * Add a callable to read stdout |
||
40 | * |
||
41 | * @param callable $callback |
||
42 | */ |
||
43 | 2 | public function onStdout(callable $callback) |
|
47 | |||
48 | /** |
||
49 | * Add a callable to read stderr |
||
50 | * |
||
51 | * @param callable $callback |
||
52 | */ |
||
53 | public function onStderr(callable $callback) |
||
57 | |||
58 | /** |
||
59 | * Read a frame in the stream |
||
60 | */ |
||
61 | 2 | protected function readFrame() |
|
89 | |||
90 | /** |
||
91 | * Force to have something of the expected size (block) |
||
92 | * |
||
93 | * @param $length |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 2 | private function forceRead($length) |
|
107 | |||
108 | /** |
||
109 | * Wait for stream to finish and call callables if defined |
||
110 | */ |
||
111 | 2 | public function wait() |
|
117 | } |
||
118 |