1 | <?php |
||
5 | class StreamBuffer implements BufferInterface |
||
6 | { |
||
7 | const READ_LENGTH = 128; |
||
8 | |||
9 | /** @var string */ |
||
10 | protected $contents; |
||
11 | /** @var int */ |
||
12 | protected $length; |
||
13 | /** @var int */ |
||
14 | protected $position; |
||
15 | /** @var bool */ |
||
16 | protected $eof = false; |
||
17 | /** @var int */ |
||
18 | protected $minSize; |
||
19 | |||
20 | /** @var resource */ |
||
21 | private $stream; |
||
22 | /** @var int */ |
||
23 | private $readLength; |
||
24 | |||
25 | /** |
||
26 | * Create a buffer around a stream |
||
27 | * |
||
28 | * @param resource $stream |
||
29 | * @param int $readLength |
||
30 | * @param int $minSize |
||
31 | */ |
||
32 | public function __construct($stream, $readLength = self::READ_LENGTH, $minSize = -1) |
||
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | public function getContents() |
||
49 | |||
50 | /** |
||
51 | * @return int |
||
52 | */ |
||
53 | public function getLength() |
||
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | public function isEof() |
||
65 | |||
66 | /** |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function read() |
||
83 | |||
84 | /** |
||
85 | * Remove the first $length characters from the buffer |
||
86 | * |
||
87 | * @param int $length |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function move($length) |
||
99 | |||
100 | /** |
||
101 | * Determine if we can read more from the stream |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | private function canRead() |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isSourceEof() |
||
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getPosition() |
||
126 | |||
127 | /** |
||
128 | * @return int |
||
129 | */ |
||
130 | public function getMinBufferSize() |
||
134 | |||
135 | /** |
||
136 | * @param int $size |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function setMinBufferSize($size) |
||
145 | } |
||
146 |