Open Journal Systems  3.3.0
Http\Message\Stream\BufferedStream Class Reference
Inheritance diagram for Http\Message\Stream\BufferedStream:
Psr\Http\Message\StreamInterface

Public Member Functions

 __construct (StreamInterface $stream, $useFileBuffer=true, $memoryBuffer=2097152)
 
 __toString ()
 
 close ()
 
 detach ()
 
 eof ()
 
 getContents ()
 
 getMetadata ($key=null)
 
 getSize ()
 
 isReadable ()
 
 isSeekable ()
 
 isWritable ()
 
 read ($length)
 
 rewind ()
 
 seek ($offset, $whence=SEEK_SET)
 
 tell ()
 
 write ($string)
 

Detailed Description

Decorator to make any stream seekable.

Internally it buffers an existing StreamInterface into a php://temp resource (or memory). By default it will use 2 megabytes of memory before writing to a temporary disk file.

Due to this, very large stream can suffer performance issue (i/o slowdown).

Definition at line 15 of file BufferedStream.php.

Constructor & Destructor Documentation

◆ __construct()

Http\Message\Stream\BufferedStream::__construct ( StreamInterface  $stream,
  $useFileBuffer = true,
  $memoryBuffer = 2097152 
)
Parameters
StreamInterface$streamDecorated stream
bool$useFileBufferWhether to use a file buffer (write to a file, if data exceed a certain size) by default, set this to false to only use memory
int$memoryBufferIn conjunction with using file buffer, limit (in bytes) from which it begins to buffer the data in a file

Definition at line 48 of file BufferedStream.php.

Member Function Documentation

◆ __toString()

Http\Message\Stream\BufferedStream::__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.

See also
http://php.net/manual/en/language.oop5.magic.php#object.tostring
Returns
string
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 67 of file BufferedStream.php.

References Http\Message\Stream\BufferedStream\getContents(), and Http\Message\Stream\BufferedStream\rewind().

◆ close()

Http\Message\Stream\BufferedStream::close ( )

{Closes the stream and any underlying resources.

Returns
void
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 83 of file BufferedStream.php.

◆ detach()

Http\Message\Stream\BufferedStream::detach ( )

{Separates any underlying resources from the stream.After the stream has been detached, the stream is in an unusable state.

Returns
resource|null Underlying PHP stream, if any
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 96 of file BufferedStream.php.

References Http\Message\Stream\BufferedStream\getContents().

◆ eof()

Http\Message\Stream\BufferedStream::eof ( )

{Returns true if the stream is at the end of the stream.

Returns
bool
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 144 of file BufferedStream.php.

Referenced by Http\Message\Stream\BufferedStream\getContents().

◆ getContents()

Http\Message\Stream\BufferedStream::getContents ( )

{Returns the remaining contents in a string

Returns
string
Exceptions
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 242 of file BufferedStream.php.

References Http\Message\Stream\BufferedStream\eof(), and Http\Message\Stream\BufferedStream\read().

Referenced by Http\Message\Stream\BufferedStream\__toString(), and Http\Message\Stream\BufferedStream\detach().

◆ getMetadata()

Http\Message\Stream\BufferedStream::getMetadata (   $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.string $key Specific metadata to retrieve. 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.}

Implements Psr\Http\Message\StreamInterface.

Definition at line 260 of file BufferedStream.php.

◆ getSize()

Http\Message\Stream\BufferedStream::getSize ( )

{Get the size of the stream if known.

Returns
int|null Returns the size in bytes if known, or null if unknown.
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 116 of file BufferedStream.php.

◆ isReadable()

Http\Message\Stream\BufferedStream::isReadable ( )

{Returns whether or not the stream is readable.

Returns
bool
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 205 of file BufferedStream.php.

◆ isSeekable()

Http\Message\Stream\BufferedStream::isSeekable ( )

{Returns whether or not the stream is seekable.

Returns
bool
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 157 of file BufferedStream.php.

◆ isWritable()

Http\Message\Stream\BufferedStream::isWritable ( )

{Returns whether or not the stream is writable.

Returns
bool
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 189 of file BufferedStream.php.

◆ read()

Http\Message\Stream\BufferedStream::read (   $length)

{Read data from the stream.

Parameters
int$lengthRead up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Returns
string Returns the data read from the stream, or an empty string if no bytes are available.
Exceptions
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 213 of file BufferedStream.php.

Referenced by Http\Message\Stream\BufferedStream\getContents().

◆ rewind()

Http\Message\Stream\BufferedStream::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).

See also
seek() on failure.
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 177 of file BufferedStream.php.

Referenced by Http\Message\Stream\BufferedStream\__toString().

◆ seek()

◆ tell()

Http\Message\Stream\BufferedStream::tell ( )

{Returns the current position of the file read/write pointer

Returns
int Position of the file pointer
Exceptions
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 132 of file BufferedStream.php.

◆ write()

Http\Message\Stream\BufferedStream::write (   $string)

{Write data to the stream.

Parameters
string$stringThe string that is to be written.
Returns
int Returns the number of bytes written to the stream.
Exceptions
}

Implements Psr\Http\Message\StreamInterface.

Definition at line 197 of file BufferedStream.php.


The documentation for this class was generated from the following file: