‪TYPO3CMS  10.4
TYPO3\CMS\Core\Http\Stream Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\Stream:

Public Member Functions

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

Protected Attributes

resource $resource
 
string 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/

Note that this is not public API yet.

Definition at line 28 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$mode‪Mode with which to open stream
Exceptions

Definition at line 46 of file Stream.php.

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

Member Function Documentation

◆ __toString()

string 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
https://php.net/manual/en/language.oop5.magic.php#object.tostring
Returns
‪string

Definition at line 72 of file Stream.php.

References TYPO3\CMS\Core\Http\Stream\getContents(), TYPO3\CMS\Core\Http\Stream\isReadable(), and TYPO3\CMS\Core\Http\Stream\rewind().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\toStringSerializationReturnsEmptyStringWhenStreamIsNotReadable().

◆ 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 338 of file Stream.php.

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

◆ close()

◆ detach()

◆ eof()

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

◆ getContents()

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

Returns the remaining contents in a string

Returns
‪string
Exceptions

Definition at line 292 of file Stream.php.

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

Referenced by TYPO3\CMS\Core\Http\Stream\__toString(), and TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\getContentsReturnsEmptyStringIfStreamIsNotReadable().

◆ getMetadata()

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

◆ getSize()

int null 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 116 of file Stream.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\getSizeReturnsStreamSize().

◆ isReadable()

◆ isSeekable()

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

◆ isWritable()

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

◆ read()

string TYPO3\CMS\Core\Http\Stream::read (   $length)

Read data from the stream.

Parameters
int$length‪Read 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 270 of file Stream.php.

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

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\readRaisesExceptionWhenStreamIsDetached(), and TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\readReturnsEmptyStringWhenAtEndOfFile().

◆ 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 208 of file Stream.php.

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

Referenced by TYPO3\CMS\Core\Http\Stream\__toString(), and TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\rewindResetsToStartOfStream().

◆ seek()

◆ tell()

◆ write()

int TYPO3\CMS\Core\Http\Stream::write (   $string)

Write data to the stream.

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

Definition at line 234 of file Stream.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\StreamTest\writeRaisesExceptionWhenStreamIsDetached().

Member Data Documentation

◆ $resource

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

The actual PHP resource

Definition at line 33 of file Stream.php.

Referenced by TYPO3\CMS\Core\Http\Stream\attach(), TYPO3\CMS\Core\Http\Stream\close(), and TYPO3\CMS\Core\Http\Stream\detach().

◆ $stream

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

Definition at line 37 of file Stream.php.

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