@@ 20-36 (lines=17) @@ | ||
17 | */ |
|
18 | private $stream; |
|
19 | ||
20 | public function __construct($stream = null) |
|
21 | { |
|
22 | if ($stream === null) { |
|
23 | $stream = STDIN; |
|
24 | } |
|
25 | ||
26 | if (!is_resource($stream) || get_resource_type($stream) !== 'stream') { |
|
27 | throw new \InvalidArgumentException('Expected a valid stream'); |
|
28 | } |
|
29 | ||
30 | $meta = stream_get_meta_data($stream); |
|
31 | if (strpos($meta['mode'], 'r') === false && strpos($meta['mode'], '+') === false) { |
|
32 | throw new \InvalidArgumentException('Expected a readable stream'); |
|
33 | } |
|
34 | ||
35 | $this->stream = $stream; |
|
36 | } |
|
37 | ||
38 | public function read(int $numBytes, callable $callback) : void |
|
39 | { |
@@ 20-36 (lines=17) @@ | ||
17 | */ |
|
18 | private $stream; |
|
19 | ||
20 | public function __construct($stream = null) |
|
21 | { |
|
22 | if ($stream === null) { |
|
23 | $stream = STDOUT; |
|
24 | } |
|
25 | ||
26 | if (!is_resource($stream) || get_resource_type($stream) !== 'stream') { |
|
27 | throw new \InvalidArgumentException('Expected a valid stream'); |
|
28 | } |
|
29 | ||
30 | $meta = stream_get_meta_data($stream); |
|
31 | if (strpos($meta['mode'], 'r') !== false && strpos($meta['mode'], '+') === false) { |
|
32 | throw new \InvalidArgumentException('Expected a writable stream'); |
|
33 | } |
|
34 | ||
35 | $this->stream = $stream; |
|
36 | } |
|
37 | ||
38 | public function write(string $buffer): void |
|
39 | { |