1 | <?php |
||
2 | |||
3 | namespace WebStream\IO; |
||
4 | |||
5 | /** |
||
6 | * ConsoleOutputStream |
||
7 | * @author Ryuichi TANAKA. |
||
8 | * @since 2016/02/27 |
||
9 | * @version 0.7 |
||
10 | */ |
||
11 | class ConsoleOutputStream extends OutputStream |
||
12 | { |
||
13 | /** |
||
14 | * constructor |
||
15 | */ |
||
16 | 4 | public function __construct() |
|
17 | { |
||
18 | 4 | parent::__construct(""); |
|
19 | } |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | 4 | public function write($buf, int $off = null, int $len = null) |
|
25 | { |
||
26 | $data = null; |
||
27 | 4 | if ($off === null && $len === null) { |
|
28 | 4 | $data = $buf; |
|
29 | 3 | } elseif ($off !== null && $len === null) { |
|
30 | 1 | $data = substr($buf, $off); |
|
31 | 2 | } elseif ($off === null && $len !== null) { |
|
32 | 1 | $data = substr($buf, 0, $len); |
|
33 | } else { |
||
34 | 1 | $data = substr($buf, $off, $len); |
|
35 | } |
||
36 | |||
37 | 4 | $this->stream .= $data; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | 4 | public function close() |
|
44 | { |
||
45 | 4 | $this->stream = null; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 4 | public function flush() |
|
52 | { |
||
53 | 4 | echo $this->stream; |
|
54 | } |
||
55 | } |
||
56 |