As the name says, it is made to be basic and direct.
Stream class Describes a data stream.
Typically, an instance will wrap a PHP stream; this interface provides a wrapper around the most common operations, including serialization of the entire stream to a string.
Psr\Http\Message\StreamInterface, Stringable
Name | Description |
---|---|
__construct | Function __construct |
__toString | Function __toString |
Reads all data from the stream into a string, from the beginning to end. | |
close | Function close |
detach | Function detach |
Separates any underlying resources from the stream. | |
eof | Function eof |
Returns true if the stream is at the end of the stream. | |
getContents | Function getContents |
Returns the remaining contents in a string | |
getMetadata | Function getMetadata |
Get stream metadata as an associative array or retrieve a specific key. | |
getSize | Function getSize |
Get the size of the stream if known. | |
isReadable | Function isReadable |
Returns whether or not the stream is readable. | |
isSeekable | Function isSeekable |
Returns whether or not the stream is seekable. | |
isValidResource | Function isValidResource |
isWritable | Function isWritable |
Returns whether or not the stream is writable. | |
read | Function read |
Read data from the stream. | |
rewind | Function rewind |
Seek to the beginning of the stream. | |
seek | Function seek |
Seek to a position in the stream. | |
tell | Function tell |
Returns the current position of the file read/write pointer | |
write | Function write |
Write data to the stream. |
Description
public __construct (resource $resource, array $options)
Function __construct
Parameters
(resource) $resource
(array) $options
Return Values
void
Description
public __toString (void)
Function __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.
Parameters
This function has no parameters.
Return Values
string
Throws Exceptions
\Exception
Description
public close (void)
Function close
Parameters
This function has no parameters.
Return Values
void
Description
public detach (void)
Function detach Separates any underlying resources from the stream.
After the stream has been detached, the stream is in an unusable state.
Parameters
This function has no parameters.
Return Values
\resource|null
Underlying PHP stream, if any
Description
public eof (void)
Function eof Returns true if the stream is at the end of the stream.
Parameters
This function has no parameters.
Return Values
bool
Description
public getContents (void)
Function getContents Returns the remaining contents in a string
Parameters
This function has no parameters.
Return Values
string
Throws Exceptions
\RuntimeException
if unable to read or an error occurs while
reading.
Description
public getMetadata (string $key)
Function getMetadata 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.
Parameters
(string) $key
Return Values
array|mixed|null
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.
Description
public getSize (void)
Function getSize Get the size of the stream if known.
Parameters
This function has no parameters.
Return Values
int|null
Returns the size in bytes if known, or null if unknown.
Description
public isReadable (void)
Function isReadable Returns whether or not the stream is readable.
Parameters
This function has no parameters.
Return Values
bool
Description
public isSeekable (void)
Function isSeekable Returns whether or not the stream is seekable.
Parameters
This function has no parameters.
Return Values
bool
Description
public isValidResource (void)
Function isValidResource
Parameters
This function has no parameters.
Return Values
bool
Description
public isWritable (void)
Function isWritable Returns whether or not the stream is writable.
Parameters
This function has no parameters.
Return Values
bool
Description
public read (int $length)
Function read Read data from the stream.
Parameters
(int) $length
Return Values
string
Returns the data read from the stream, or an empty string
if no bytes are available.
Throws Exceptions
\RuntimeException
if an error occurs.
Description
public rewind (void)
Function rewind Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception;
otherwise, it will perform a seek(0).
Parameters
This function has no parameters.
Return Values
void
Throws Exceptions
\RuntimeException
on failure.
Description
public seek (int $offset, int $whence)
Function seek Seek to a position in the stream.
Parameters
(int) $offset
(int) $whence
fseek()
. SEEK_SET: Set position equal toReturn Values
void
Throws Exceptions
\RuntimeException
on failure.
Description
public tell (void)
Function tell Returns the current position of the file read/write pointer
Parameters
This function has no parameters.
Return Values
int
Position of the file pointer
Throws Exceptions
\RuntimeException
on error.
Description
public write (string $string)
Function write Write data to the stream.
Parameters
(string) $string
Return Values
int
Returns the number of bytes written to the stream.
Throws Exceptions
\RuntimeException
on failure.