TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Http\Stream Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\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()

TYPO3\CMS\Core\Http\Stream::__construct (   $stream,
  $mode = 'r' 
)

Constructor setting up the PHP resource

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

Definition at line 47 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\$stream.

Member Function Documentation

◆ __toString()

TYPO3\CMS\Core\Http\Stream::__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 TYPO3\CMS\Core\Http\Stream\getContents(), TYPO3\CMS\Core\Http\Stream\isReadable(), and TYPO3\CMS\Core\Http\Stream\rewind().

◆ attach()

TYPO3\CMS\Core\Http\Stream::attach (   $resource,
  $mode = 'r' 
)

Attach a new stream/resource to the instance.

Parameters
string | resource$resource
string$mode
Exceptions

Definition at line 341 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\$resource.

◆ close()

TYPO3\CMS\Core\Http\Stream::close ( )

Closes the stream and any underlying resources.

Returns
void

Definition at line 91 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\$resource, and TYPO3\CMS\Core\Http\Stream\detach().

◆ detach()

TYPO3\CMS\Core\Http\Stream::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 TYPO3\CMS\Core\Http\Stream\$resource.

Referenced by TYPO3\CMS\Core\Http\Stream\close().

◆ eof()

TYPO3\CMS\Core\Http\Stream::eof ( )

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

Returns
bool

Definition at line 151 of file Stream.php.

◆ getContents()

TYPO3\CMS\Core\Http\Stream::getContents ( )

Returns the remaining contents in a string

Returns
string
Exceptions

Definition at line 295 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\isReadable().

Referenced by TYPO3\CMS\Core\Http\Stream\__toString().

◆ getMetadata()

TYPO3\CMS\Core\Http\Stream::getMetadata (   $key = null)

◆ getSize()

TYPO3\CMS\Core\Http\Stream::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()

TYPO3\CMS\Core\Http\Stream::isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Definition at line 254 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\getMetadata().

Referenced by TYPO3\CMS\Core\Http\Stream\__toString(), TYPO3\CMS\Core\Http\Stream\getContents(), and TYPO3\CMS\Core\Http\Stream\read().

◆ isSeekable()

TYPO3\CMS\Core\Http\Stream::isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Definition at line 164 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\getMetadata().

Referenced by TYPO3\CMS\Core\Http\Stream\seek().

◆ isWritable()

TYPO3\CMS\Core\Http\Stream::isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Definition at line 221 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\getMetadata().

◆ read()

TYPO3\CMS\Core\Http\Stream::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

Definition at line 273 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\isReadable().

◆ rewind()

TYPO3\CMS\Core\Http\Stream::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 TYPO3\CMS\Core\Http\Stream\seek().

Referenced by TYPO3\CMS\Core\Http\Stream\__toString().

◆ seek()

◆ tell()

TYPO3\CMS\Core\Http\Stream::tell ( )

Returns the current position of the file read/write pointer

Returns
int Position of the file pointer
Exceptions

Definition at line 134 of file Stream.php.

◆ write()

TYPO3\CMS\Core\Http\Stream::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

Definition at line 237 of file Stream.php.

Member Data Documentation

◆ $resource

TYPO3\CMS\Core\Http\Stream::$resource
protected

◆ $stream

TYPO3\CMS\Core\Http\Stream::$stream
protected

Definition at line 38 of file Stream.php.

Referenced by TYPO3\CMS\Core\Http\Stream\__construct().