1 | <?php |
||
26 | class ProcessStream implements \Psr\Http\Message\StreamInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var resource |
||
30 | */ |
||
31 | private $process; |
||
32 | /** |
||
33 | * @var resource|null |
||
34 | */ |
||
35 | private $stream; |
||
36 | |||
37 | /** |
||
38 | * @param string $input The data to write to the process' stdin |
||
39 | * @param string $process The process to execute |
||
40 | * @throws \RuntimeException |
||
41 | */ |
||
42 | public function __construct(string $input, string $process) |
||
58 | |||
59 | /** |
||
60 | * Closes the stream and any underlying resources. |
||
61 | */ |
||
62 | public function close(): void |
||
70 | |||
71 | /** |
||
72 | * Separates any underlying resources from the stream. |
||
73 | * |
||
74 | * After the stream has been detached, the stream is in an unusable state. |
||
75 | * |
||
76 | * @return resource|null Underlying PHP stream, if any |
||
77 | */ |
||
78 | public function detach() |
||
84 | |||
85 | /** |
||
86 | * Returns true if the stream is at the end of the stream. |
||
87 | * |
||
88 | * @return - Whether the stream pointer is at the end |
||
|
|||
89 | */ |
||
90 | public function eof(): bool |
||
94 | |||
95 | /** |
||
96 | * Returns the remaining contents in a string. |
||
97 | * |
||
98 | * @return - The stream contents |
||
99 | * @throws \RuntimeException if unable to read or an error occurs while reading |
||
100 | */ |
||
101 | public function getContents(): string |
||
112 | |||
113 | /** |
||
114 | * Get stream metadata as an associative array or retrieve a specific key. |
||
115 | * |
||
116 | * The keys returned are identical to the keys returned from PHP's |
||
117 | * `stream_get_meta_data` function. |
||
118 | * |
||
119 | * @param string|null $key Specific metadata to retrieve. |
||
120 | * @return array<string,mixed>|mixed|null Returns an associative array if no key is provided. Returns a |
||
121 | * specific key value if a key is provided and the value is found, or |
||
122 | * null if the key is not found. |
||
123 | */ |
||
124 | public function getMetadata($key = null) |
||
133 | |||
134 | /** |
||
135 | * Get the size of the stream if known. |
||
136 | * |
||
137 | * @return int|null Returns the size in bytes if known, or null if unknown. |
||
138 | */ |
||
139 | public function getSize(): ?int |
||
143 | |||
144 | /** |
||
145 | * Returns whether or not the stream is readable. |
||
146 | * |
||
147 | * @return bool Whether or not the stream is readable |
||
148 | */ |
||
149 | public function isReadable(): bool |
||
153 | |||
154 | /** |
||
155 | * Returns whether or not the stream is seekable. |
||
156 | * |
||
157 | * @return bool Whether the stream is seekable |
||
158 | */ |
||
159 | public function isSeekable(): bool |
||
163 | |||
164 | /** |
||
165 | * Returns whether or not the stream is writable. |
||
166 | * |
||
167 | * @return bool Whether the stream is writable |
||
168 | */ |
||
169 | public function isWritable(): bool |
||
173 | |||
174 | /** |
||
175 | * Read data from the stream. |
||
176 | * |
||
177 | * @param $length - Read up to $length bytes from the object and return |
||
178 | * them. Fewer than $length bytes may be returned if underlying stream |
||
179 | * call returns fewer bytes. |
||
180 | * @return string Returns the data read from the stream, or an empty string |
||
181 | * if no bytes are available |
||
182 | * @throws \RuntimeException if an error occurs |
||
183 | */ |
||
184 | public function read($length): string |
||
195 | |||
196 | /** |
||
197 | * Seek to the beginning of the stream. |
||
198 | * |
||
199 | * This stream is not seekable, this method will raise an exception if the |
||
200 | * stream pointer is not at the beginning. |
||
201 | * |
||
202 | * @throws \RuntimeException on failure. |
||
203 | */ |
||
204 | public function rewind(): void |
||
211 | |||
212 | /** |
||
213 | * Seek to a position in the stream. |
||
214 | * |
||
215 | * @param $offset - Stream offset |
||
216 | * @param $whence - Specifies how the cursor position will be calculated |
||
217 | * based on the seek offset. Valid values are identical to the built-in |
||
218 | * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to |
||
219 | * offset bytes SEEK_CUR: Set position to current location plus offset |
||
220 | * SEEK_END: Set position to end-of-stream plus offset. |
||
221 | * @throws \RuntimeException on failure. |
||
222 | */ |
||
223 | public function seek($offset, $whence = SEEK_SET): void |
||
230 | |||
231 | /** |
||
232 | * Returns the current position of the file read/write pointer |
||
233 | * |
||
234 | * @return int Position of the file pointer |
||
235 | * @throws \RuntimeException on error. |
||
236 | */ |
||
237 | public function tell(): int |
||
248 | |||
249 | /** |
||
250 | * Write data to the stream. |
||
251 | * |
||
252 | * This stream is not writable, this method will raise an exception. |
||
253 | * |
||
254 | * @param $string - The string that is to be written |
||
255 | * @return int Returns the number of bytes written to the stream. |
||
256 | * @throws \RuntimeException on failure |
||
257 | */ |
||
258 | public function write($string): int |
||
262 | |||
263 | /** |
||
264 | * Reads all data from the stream into a string, from the beginning to end. |
||
265 | * |
||
266 | * This method MUST attempt to seek to the beginning of the stream before |
||
267 | * reading data and read the stream until the end is reached. |
||
268 | * |
||
269 | * Warning: This could attempt to load a large amount of data into memory. |
||
270 | * |
||
271 | * This method MUST NOT raise an exception in order to conform with PHP's |
||
272 | * string casting operations. |
||
273 | * |
||
274 | * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring |
||
275 | * @return - string |
||
276 | */ |
||
277 | public function __toString(): string |
||
289 | } |
||
290 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.