1 | <?php |
||
8 | final class Buffer implements StreamWrapper |
||
9 | { |
||
10 | /** @var string */ |
||
11 | private $stream = ''; |
||
12 | |||
13 | /** @var int */ |
||
14 | private $position = 0; |
||
15 | |||
16 | /** @var int */ |
||
17 | private $readCount = 0; |
||
18 | |||
19 | /** @var int */ |
||
20 | private $writeCount = 0; |
||
21 | |||
22 | /** @var array */ |
||
23 | private $limits = [ |
||
24 | 'read' => -1, |
||
25 | 'read_after' => 0, |
||
26 | 'read_every' => 1, |
||
27 | 'write' => -1, |
||
28 | 'write_after' => 0, |
||
29 | 'write_every' => 1, |
||
30 | ]; |
||
31 | |||
32 | 11 | public function stream_open($path, $mode, $options, &$opened_path) |
|
46 | |||
47 | 7 | public function stream_eof() |
|
51 | |||
52 | 3 | public function stream_tell() |
|
56 | |||
57 | 8 | public function stream_write($data) |
|
72 | |||
73 | 3 | public function stream_read($count) |
|
74 | { |
||
75 | 3 | ++$this->readCount; |
|
76 | |||
77 | 3 | if (!$this->canRead()) { |
|
78 | 1 | return false; |
|
79 | } |
||
80 | |||
81 | 3 | $data = substr($this->stream, $this->position, $count); |
|
82 | |||
83 | 3 | if (false === $data) { |
|
84 | 1 | return false; |
|
85 | } |
||
86 | |||
87 | 2 | $this->position += strlen($data); |
|
88 | |||
89 | 2 | return $data; |
|
90 | } |
||
91 | |||
92 | 3 | public function stream_seek($offset, $whence) |
|
93 | { |
||
94 | 3 | static $values = [SEEK_SET, SEEK_CUR, SEEK_END]; |
|
95 | |||
96 | 3 | if (in_array($whence, $values)) { |
|
97 | 3 | if (SEEK_END === $whence) { |
|
98 | 1 | $offset = strlen($this->stream) + $offset; |
|
99 | } |
||
100 | |||
101 | 3 | if ($offset >= 0) { |
|
102 | 3 | $this->position = $offset; |
|
103 | 3 | return true; |
|
104 | } |
||
105 | } |
||
106 | |||
107 | return false; |
||
108 | } |
||
109 | |||
110 | 2 | public function stream_stat() |
|
114 | |||
115 | 2 | public function stream_truncate($new_size) |
|
130 | |||
131 | 1 | public function stream_set_option($option, $arg1, $arg2) |
|
135 | |||
136 | 11 | private function configureLimits(array $query): void |
|
150 | |||
151 | 3 | private function canRead(): bool |
|
159 | |||
160 | 8 | private function canWrite(): bool |
|
168 | } |
||
169 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.