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