1 | <?php |
||
16 | class StreamBuffer implements BufferInterface |
||
17 | { |
||
18 | const READ_LENGTH = 128; |
||
19 | |||
20 | /** @var string */ |
||
21 | protected $contents; |
||
22 | /** @var int */ |
||
23 | protected $length; |
||
24 | /** @var int */ |
||
25 | protected $position; |
||
26 | /** @var bool */ |
||
27 | protected $eof = false; |
||
28 | /** @var int */ |
||
29 | protected $minSize; |
||
30 | |||
31 | /** @var resource */ |
||
32 | private $stream; |
||
33 | /** @var int */ |
||
34 | private $readLength; |
||
35 | |||
36 | /** |
||
37 | * Create a buffer around a stream |
||
38 | * |
||
39 | * @param resource $stream |
||
40 | * @param int $readLength |
||
41 | * @param int $minSize |
||
42 | */ |
||
43 | 33 | public function __construct($stream, $readLength = self::READ_LENGTH, $minSize = -1) |
|
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | 31 | public function getContents() |
|
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | 28 | public function getLength() |
|
68 | |||
69 | /** |
||
70 | * @return bool |
||
71 | */ |
||
72 | 30 | public function isEof() |
|
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | 33 | public function read() |
|
94 | |||
95 | /** |
||
96 | * Remove the first $length characters from the buffer |
||
97 | * |
||
98 | * @param int $length |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | 28 | public function move($length) |
|
110 | |||
111 | /** |
||
112 | * Determine if we can read more from the stream |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | 33 | private function canRead() |
|
121 | |||
122 | /** |
||
123 | * @return bool |
||
124 | */ |
||
125 | 1 | public function isSourceEof() |
|
129 | |||
130 | /** |
||
131 | * @return int |
||
132 | */ |
||
133 | 28 | public function getPosition() |
|
137 | |||
138 | /** |
||
139 | * @return int |
||
140 | */ |
||
141 | 1 | public function getMinBufferSize() |
|
145 | |||
146 | /** |
||
147 | * @param int $size |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | 4 | public function setMinBufferSize($size) |
|
156 | } |
||
157 |