ProcessStream
Implementation of PSR HTTP streams for processes
Constructors / Destructors
| Returns | Signature and Description |
|---|---|
void | __construct(, ) |
Instance Methods
| Returns | Signature and Description |
|---|---|
string | Reads all data from the stream into a string, from the beginning to end. |
void | close()Closes the stream and any underlying resources. |
?resource | detach()Separates any underlying resources from the stream. |
bool | eof()Returns true if the stream is at the end of the stream. |
string | Returns the remaining contents in a string. |
mixed | getMetadata()Get stream metadata as an associative array or retrieve a specific key. |
?int | getSize()Get the size of the stream if known. |
bool | Returns whether or not the stream is readable. |
bool | Returns whether or not the stream is seekable. |
bool | Returns whether or not the stream is writable. |
string | read()Read data from the stream. |
void | rewind()Seek to the beginning of the stream. |
void | seek(, )Seek to a position in the stream. |
int | tell()Returns the current position of the file read/write pointer |
int | write()Write data to the stream. |
Method Details
__construct
__construct(string $input, string $process)| Name | Type | Description |
|---|---|---|
$input | string | The data to write to the process' stdin |
$process | string | The process to execute |
| Type | Conditions |
|---|---|
InvalidArgumentException |
__toString
__toString()Reads all data from the stream into a string, from the beginning to end.
This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.
Warning: This could attempt to load a large amount of data into memory.
This method MUST NOT raise an exception in order to conform with PHP's string casting operations.
| Type | Description |
|---|---|
string | string |
close
close()Closes the stream and any underlying resources.
detach
detach()Separates any underlying resources from the stream.
After the stream has been detached, the stream is in an unusable state.
| Type | Description |
|---|---|
?resource | Underlying PHP stream, if any |
eof
eof()Returns true if the stream is at the end of the stream.
| Type | Description |
|---|---|
bool | Whether the stream pointer is at the end |
getContents
getContents()Returns the remaining contents in a string.
| Type | Description |
|---|---|
string | The stream contents |
| Type | Conditions |
|---|---|
RuntimeException | if unable to read or an error occurs while reading |
getMetadata
getMetadata(?string $key = null)Get stream metadata as an associative array or retrieve a specific key.
The keys returned are identical to the keys returned from PHP's
stream_get_meta_data function.
| Name | Type | Description |
|---|---|---|
$key | ?string | Specific metadata to retrieve. |
| Type | Description |
|---|---|
mixed | Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found. |
getSize
getSize()Get the size of the stream if known.
| Type | Description |
|---|---|
?int | Returns the size in bytes if known, or null if unknown. |
isReadable
isReadable()Returns whether or not the stream is readable.
| Type | Description |
|---|---|
bool | Whether or not the stream is readable |
isSeekable
isSeekable()Returns whether or not the stream is seekable.
| Type | Description |
|---|---|
bool | Whether the stream is seekable |
isWritable
isWritable()Returns whether or not the stream is writable.
| Type | Description |
|---|---|
bool | Whether the stream is writable |
read
read(mixed $length)Read data from the stream.
| Name | Type | Description |
|---|---|---|
$length | Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes. |
| Type | Description |
|---|---|
string | Returns the data read from the stream, or an empty string if no bytes are available |
| Type | Conditions |
|---|---|
RuntimeException | if an error occurs |
rewind
rewind()Seek to the beginning of the stream.
This stream is not seekable, this method will raise an exception if the stream pointer is not at the beginning.
| Type | Conditions |
|---|---|
RuntimeException | on failure. |
seek
seek(mixed $offset, mixed $whence = SEEK_SET)Seek to a position in the stream.
| Name | Type | Description |
|---|---|---|
$offset | Stream offset | |
$whence | Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for |
| Type | Conditions |
|---|---|
RuntimeException | on failure. |
tell
tell()Returns the current position of the file read/write pointer
| Type | Description |
|---|---|
int | Position of the file pointer |
| Type | Conditions |
|---|---|
RuntimeException | on error. |
write
write(mixed $string)Write data to the stream.
This stream is not writable, this method will raise an exception.
| Name | Type | Description |
|---|---|---|
$string | The string that is to be written |
| Type | Description |
|---|---|
int | Returns the number of bytes written to the stream. |
| Type | Conditions |
|---|---|
RuntimeException | on failure |