ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
GuzzleHttp\Psr7\DroppingStream Class Reference

Stream decorator that begins dropping data once the size of the underlying stream becomes too full. More...

+ Inheritance diagram for GuzzleHttp\Psr7\DroppingStream:
+ Collaboration diagram for GuzzleHttp\Psr7\DroppingStream:

Public Member Functions

 __construct (StreamInterface $stream, $maxLength)
 
 write ($string)
 Write data to the stream. More...
 
- Public Member Functions inherited from Psr\Http\Message\StreamInterface
 __toString ()
 Reads all data from the stream into a string, from the beginning to end. More...
 
 close ()
 Closes the stream and any underlying resources. More...
 
 detach ()
 Separates any underlying resources from the stream. More...
 
 getSize ()
 Get the size of the stream if known. More...
 
 tell ()
 Returns the current position of the file read/write pointer. More...
 
 eof ()
 Returns true if the stream is at the end of the stream. More...
 
 isSeekable ()
 Returns whether or not the stream is seekable. More...
 
 seek ($offset, $whence=SEEK_SET)
 Seek to a position in the stream. More...
 
 rewind ()
 Seek to the beginning of the stream. More...
 
 isWritable ()
 Returns whether or not the stream is writable. More...
 
 isReadable ()
 Returns whether or not the stream is readable. More...
 
 read ($length)
 Read data from the stream. More...
 
 getContents ()
 Returns the remaining contents in a string. More...
 
 getMetadata ($key=null)
 Get stream metadata as an associative array or retrieve a specific key. More...
 

Private Attributes

 $maxLength
 

Detailed Description

Stream decorator that begins dropping data once the size of the underlying stream becomes too full.

Definition at line 10 of file DroppingStream.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\DroppingStream::__construct ( StreamInterface  $stream,
  $maxLength 
)
Parameters
StreamInterface$streamUnderlying stream to decorate.
int$maxLengthMaximum size before dropping data.

Definition at line 20 of file DroppingStream.php.

References GuzzleHttp\Psr7\DroppingStream\$maxLength, and GuzzleHttp\Psr7\$stream.

21  {
22  $this->stream = $stream;
23  $this->maxLength = $maxLength;
24  }
$stream
PHP stream implementation.

Member Function Documentation

◆ write()

GuzzleHttp\Psr7\DroppingStream::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 26 of file DroppingStream.php.

27  {
28  $diff = $this->maxLength - $this->stream->getSize();
29 
30  // Begin returning 0 when the underlying stream is too large.
31  if ($diff <= 0) {
32  return 0;
33  }
34 
35  // Write the stream or a subset of the stream if needed.
36  if (strlen($string) < $diff) {
37  return $this->stream->write($string);
38  }
39 
40  return $this->stream->write(substr($string, 0, $diff));
41  }

Field Documentation

◆ $maxLength

GuzzleHttp\Psr7\DroppingStream::$maxLength
private

Definition at line 14 of file DroppingStream.php.

Referenced by GuzzleHttp\Psr7\DroppingStream\__construct().


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