TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Stream Class Reference
Inheritance diagram for Stream:

Public Member Functions

 __construct ($stream, $mode= 'r')
 
 __toString ()
 
 close ()
 
 detach ()
 
 getSize ()
 
 tell ()
 
 eof ()
 
 isSeekable ()
 
 seek ($offset, $whence=SEEK_SET)
 
 rewind ()
 
 isWritable ()
 
 write ($string)
 
 isReadable ()
 
 read ($length)
 
 getContents ()
 
 getMetadata ($key=null)
 
 attach ($resource, $mode= 'r')
 

Protected Attributes

 $resource
 
 $stream
 

Detailed Description

Default implementation for the StreamInterface of the PSR-7 standard Acts mainly as a decorator class for streams/resources.

Highly inspired by https://github.com/phly/http/

Definition at line 27 of file Stream.php.

Constructor & Destructor Documentation

__construct (   $stream,
  $mode = 'r' 
)

Constructor setting up the PHP resource

Parameters
string | resource$stream
string$modeMode with which to open stream
Exceptions
InvalidArgumentException

Definition at line 47 of file Stream.php.

References Stream\$stream.

Member Function Documentation

__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

Definition at line 73 of file Stream.php.

References Stream\getContents(), Stream\isReadable(), and Stream\rewind().

attach (   $resource,
  $mode = 'r' 
)

Attach a new stream/resource to the instance.

Parameters
string | resource$resource
string$mode
Exceptions
InvalidArgumentException for stream identifier that cannot be cast to a resource
InvalidArgumentException for non-resource stream

Definition at line 341 of file Stream.php.

References Stream\$resource.

close ( )

Closes the stream and any underlying resources.

Returns
void

Definition at line 91 of file Stream.php.

References Stream\$resource, and Stream\detach().

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

Definition at line 107 of file Stream.php.

References Stream\$resource.

Referenced by Stream\close().

eof ( )

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

Returns
bool

Definition at line 151 of file Stream.php.

getContents ( )

Returns the remaining contents in a string

Returns
string
Exceptions
RuntimeException if unable to read or an error occurs while reading.

Definition at line 295 of file Stream.php.

References Stream\isReadable().

Referenced by Stream\__toString().

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.

Definition at line 321 of file Stream.php.

Referenced by Stream\isReadable(), Stream\isSeekable(), and Stream\isWritable().

getSize ( )

Get the size of the stream if known.

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

Definition at line 119 of file Stream.php.

isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Definition at line 254 of file Stream.php.

References Stream\getMetadata().

Referenced by Stream\__toString(), Stream\getContents(), and Stream\read().

isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Definition at line 164 of file Stream.php.

References Stream\getMetadata().

Referenced by Stream\seek().

isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Definition at line 221 of file Stream.php.

References Stream\getMetadata().

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
RuntimeException if an error occurs.

Definition at line 273 of file Stream.php.

References Stream\isReadable().

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.

Definition at line 211 of file Stream.php.

References Stream\seek().

Referenced by Stream\__toString().

tell ( )

Returns the current position of the file read/write pointer

Returns
int Position of the file pointer
Exceptions
RuntimeException on error.

Definition at line 134 of file Stream.php.

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
RuntimeException on failure.

Definition at line 237 of file Stream.php.

Member Data Documentation

$resource
protected

Definition at line 33 of file Stream.php.

Referenced by Stream\attach(), Stream\close(), and Stream\detach().

$stream
protected

Definition at line 38 of file Stream.php.

Referenced by Stream\__construct().