1 | <?php |
||
8 | class Stream implements StreamInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var resource |
||
12 | */ |
||
13 | protected $stream; |
||
14 | |||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | * |
||
18 | * @var array |
||
19 | * @link http://php.net/manual/function.fopen.php |
||
20 | */ |
||
21 | protected static $modes = [ |
||
22 | 'readable' => ['r', 'r+', 'w+', 'a+', 'x+', 'c+'], |
||
23 | 'writable' => ['r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+'], |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @param $stream |
||
28 | * @param $mode |
||
29 | */ |
||
30 | 49 | public function __construct($stream, $mode = 'r') |
|
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | 2 | public function close() |
|
50 | |||
51 | /** |
||
52 | * @param $resource |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 49 | public function attach($resource) |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | * |
||
69 | * @return resource|null Underlying PHP stream, if any |
||
70 | */ |
||
71 | 8 | public function detach() |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | * |
||
81 | * @return int|null Returns the size in bytes if known, or null if unknown. |
||
82 | */ |
||
83 | 3 | public function getSize() |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | * |
||
95 | * @return int Position of the file pointer |
||
96 | * @throws \RuntimeException on error. |
||
97 | */ |
||
98 | 4 | public function tell() |
|
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 3 | public function eof() |
|
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 23 | public function isSeekable() |
|
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | * |
||
130 | * @link http://www.php.net/manual/en/function.fseek.php |
||
131 | * @param int $offset Stream offset |
||
132 | * @param int $whence Specifies how the cursor position will be calculated |
||
133 | * based on the seek offset. Valid values are identical to the built-in |
||
134 | * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to |
||
135 | * offset bytes SEEK_CUR: Set position to current location plus offset |
||
136 | * SEEK_END: Set position to end-of-stream plus offset. |
||
137 | * @return bool |
||
138 | * @throws \RuntimeException on failure. |
||
139 | */ |
||
140 | 21 | public function seek($offset, $whence = SEEK_SET) |
|
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | * |
||
154 | * @see seek() |
||
155 | * @link http://www.php.net/manual/en/function.fseek.php |
||
156 | * @throws \RuntimeException on failure. |
||
157 | */ |
||
158 | 18 | public function rewind() |
|
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | 29 | public function isWritable() |
|
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | * |
||
181 | * @param string $string The string that is to be written. |
||
182 | * @return int Returns the number of bytes written to the stream. |
||
183 | * @throws \RuntimeException on failure. |
||
184 | */ |
||
185 | 27 | public function write($string) |
|
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | 20 | public function isReadable() |
|
215 | |||
216 | /** |
||
217 | * {@inheritdoc} |
||
218 | * |
||
219 | * @param int $length Read up to $length bytes from the object and return |
||
220 | * them. Fewer than $length bytes may be returned if underlying stream |
||
221 | * call returns fewer bytes. |
||
222 | * @return string Returns the data read from the stream, or an empty string |
||
223 | * if no bytes are available. |
||
224 | * @throws \RuntimeException if an error occurs. |
||
225 | */ |
||
226 | 3 | public function read($length) |
|
241 | |||
242 | /** |
||
243 | * {@inheritdoc} |
||
244 | * |
||
245 | * @return string |
||
246 | * @throws \RuntimeException if unable to read or an error occurs while |
||
247 | * reading. |
||
248 | */ |
||
249 | 16 | public function getContents() |
|
262 | |||
263 | /** |
||
264 | * {@inheritdoc} |
||
265 | * |
||
266 | * @link http://php.net/manual/en/function.stream-get-meta-data.php |
||
267 | * @param string $key Specific metadata to retrieve. |
||
268 | * @return array|mixed|null Returns an associative array if no key is |
||
269 | * provided. Returns a specific key value if a key is provided and the |
||
270 | * value is found, or null if the key is not found. |
||
271 | */ |
||
272 | 38 | public function getMetadata($key = null) |
|
286 | |||
287 | /** |
||
288 | * {@inheritdoc} |
||
289 | * |
||
290 | * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring |
||
291 | * @return string |
||
292 | */ |
||
293 | 12 | public function __toString() |
|
302 | } |
||
303 |