Basicis - Core

Logo

As the name says, it is made to be basic and direct.

View the Project on GitHub basicis/core

Basicis\Http\Message\Stream

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.

Implements:

Psr\Http\Message\StreamInterface, Stringable

Methods

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.  

Stream::__construct

Description

public __construct (resource $resource, array $options)

Function __construct

Parameters

Return Values

void


Stream::__toString

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


Stream::close

Description

public close (void)

Function close

Parameters

This function has no parameters.

Return Values

void


Stream::detach

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


Stream::eof

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


Stream::getContents

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.


Stream::getMetadata

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

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.


Stream::getSize

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.


Stream::isReadable

Description

public isReadable (void)

Function isReadable Returns whether or not the stream is readable.

Parameters

This function has no parameters.

Return Values

bool


Stream::isSeekable

Description

public isSeekable (void)

Function isSeekable Returns whether or not the stream is seekable.

Parameters

This function has no parameters.

Return Values

bool


Stream::isValidResource

Description

public isValidResource (void)

Function isValidResource

Parameters

This function has no parameters.

Return Values

bool


Stream::isWritable

Description

public isWritable (void)

Function isWritable Returns whether or not the stream is writable.

Parameters

This function has no parameters.

Return Values

bool


Stream::read

Description

public read (int $length)

Function read Read data from the stream.

Parameters

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.


Stream::rewind

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.


Stream::seek

Description

public seek (int $offset, int $whence)

Function seek Seek to a position in the stream.

Parameters

Return Values

void

Throws Exceptions

\RuntimeException

on failure.


Stream::tell

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.


Stream::write

Description

public write (string $string)

Function write Write data to the stream.

Parameters

Return Values

int

Returns the number of bytes written to the stream.

Throws Exceptions

\RuntimeException

on failure.