1 | <?php |
||
14 | abstract class FilteredStream implements StreamInterface |
||
15 | { |
||
16 | const BUFFER_SIZE = 65536; |
||
17 | |||
18 | use StreamDecorator; |
||
19 | |||
20 | /** |
||
21 | * @var callable |
||
22 | */ |
||
23 | protected $readFilterCallback; |
||
24 | |||
25 | /** |
||
26 | * @var resource |
||
27 | */ |
||
28 | protected $readFilter; |
||
29 | |||
30 | /** |
||
31 | * @var callable |
||
32 | */ |
||
33 | protected $writeFilterCallback; |
||
34 | |||
35 | /** |
||
36 | * @var resource |
||
37 | */ |
||
38 | protected $writeFilter; |
||
39 | |||
40 | /** |
||
41 | * Internal buffer. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $buffer = ''; |
||
46 | |||
47 | /** |
||
48 | * @param StreamInterface $stream |
||
49 | * @param null $readFilterOptions |
||
50 | * @param null $writeFilterOptions |
||
51 | */ |
||
52 | 32 | public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null) |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 16 | public function read($length) |
|
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 9 | public function eof() |
|
92 | |||
93 | /** |
||
94 | * Buffer is filled by reading underlying stream. |
||
95 | * |
||
96 | * Callback is reading once more even if the stream is ended. |
||
97 | * This allow to get last data in the PHP buffer otherwise this |
||
98 | * bug is present : https://bugs.php.net/bug.php?id=48725 |
||
99 | */ |
||
100 | 16 | protected function fill() |
|
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | 9 | public function getContents() |
|
129 | |||
130 | /** |
||
131 | * Return the read filter name. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | abstract public function getReadFilter(); |
||
136 | |||
137 | /** |
||
138 | * Return the write filter name. |
||
139 | * |
||
140 | * @return mixed |
||
141 | */ |
||
142 | abstract public function getWriteFilter(); |
||
143 | } |
||
144 |