(string $path, ?int $length = null, int $offset = 0)
| 158 | } |
| 159 | |
| 160 | public function read(string $path, ?int $length = null, int $offset = 0): string|false |
| 161 | { |
| 162 | $stream = $this->openReadStream($path, $length, $offset); |
| 163 | if ($stream === false) { |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | if (is_resource($stream)) { |
| 168 | $data = ($length !== null) |
| 169 | ? stream_get_contents($stream, $length) |
| 170 | : stream_get_contents($stream); |
| 171 | fclose($stream); |
| 172 | return ($data === false) ? false : $data; |
| 173 | } |
| 174 | |
| 175 | if (is_object($stream) && method_exists($stream, 'read')) { |
| 176 | $data = $stream->read($length ?? 0); |
| 177 | if (method_exists($stream, 'close')) { |
| 178 | $stream->close(); |
| 179 | } |
| 180 | return $data; |
| 181 | } |
| 182 | |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | public function openReadStream(string $path, ?int $length = null, int $offset = 0) |
| 187 | { |
no test coverage detected