ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
GuzzleHttp\Psr7\BufferStream Class Reference

Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from the buffer. More...

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

Public Member Functions

 __construct ($hwm=16384)
 
 __toString ()
 Reads all data from the stream into a string, from the beginning to end. More...
 
 getContents ()
 Returns the remaining contents in a string. 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...
 
 isReadable ()
 Returns whether or not the stream is readable. More...
 
 isWritable ()
 Returns whether or not the stream is writable. More...
 
 isSeekable ()
 Returns whether or not the stream is seekable. More...
 
 rewind ()
 Seek to the beginning of the stream. More...
 
 seek ($offset, $whence=SEEK_SET)
 Seek to a position in the stream. More...
 
 eof ()
 Returns true if the stream is at the end of the stream. More...
 
 tell ()
 Returns the current position of the file read/write pointer. More...
 
 read ($length)
 Reads data from the buffer. More...
 
 write ($string)
 Writes data to the buffer. More...
 
 getMetadata ($key=null)
 Get stream metadata as an associative array or retrieve a specific key. More...
 

Private Attributes

 $hwm
 
 $buffer = ''
 

Detailed Description

Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from the buffer.

This stream returns a "hwm" metadata value that tells upstream consumers what the configured high water mark of the stream is, or the maximum preferred size of the buffer.

Definition at line 14 of file BufferStream.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\BufferStream::__construct (   $hwm = 16384)
Parameters
int$hwmHigh water mark, representing the preferred maximum buffer size. If the size of the buffer exceeds the high water mark, then calls to write will continue to succeed but will return false to inform writers to slow down until the buffer has been drained by reading from it.

Definition at line 26 of file BufferStream.php.

References GuzzleHttp\Psr7\BufferStream\$hwm.

27  {
28  $this->hwm = $hwm;
29  }

Member Function Documentation

◆ __toString()

GuzzleHttp\Psr7\BufferStream::__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 31 of file BufferStream.php.

References GuzzleHttp\Psr7\BufferStream\getContents().

32  {
33  return $this->getContents();
34  }
getContents()
Returns the remaining contents in a string.
+ Here is the call graph for this function:

◆ close()

GuzzleHttp\Psr7\BufferStream::close ( )

Closes the stream and any underlying resources.

Returns
void

Implements Psr\Http\Message\StreamInterface.

Definition at line 44 of file BufferStream.php.

Referenced by GuzzleHttp\Psr7\BufferStream\detach().

45  {
46  $this->buffer = '';
47  }
+ Here is the caller graph for this function:

◆ detach()

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

References GuzzleHttp\Psr7\BufferStream\close().

50  {
51  $this->close();
52  }
close()
Closes the stream and any underlying resources.
+ Here is the call graph for this function:

◆ eof()

GuzzleHttp\Psr7\BufferStream::eof ( )

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

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 84 of file BufferStream.php.

85  {
86  return strlen($this->buffer) === 0;
87  }

◆ getContents()

GuzzleHttp\Psr7\BufferStream::getContents ( )

Returns the remaining contents in a string.

Returns
string
Exceptions

Implements Psr\Http\Message\StreamInterface.

Definition at line 36 of file BufferStream.php.

References GuzzleHttp\Psr7\BufferStream\$buffer.

Referenced by GuzzleHttp\Psr7\BufferStream\__toString().

37  {
39  $this->buffer = '';
40 
41  return $buffer;
42  }
+ Here is the caller graph for this function:

◆ getMetadata()

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

References GuzzleHttp\Psr7\BufferStream\$hwm, and $key.

130  {
131  if ($key == 'hwm') {
132  return $this->hwm;
133  }
134 
135  return $key ? null : [];
136  }
$key
Definition: croninfo.php:18

◆ getSize()

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

55  {
56  return strlen($this->buffer);
57  }

◆ isReadable()

GuzzleHttp\Psr7\BufferStream::isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 59 of file BufferStream.php.

60  {
61  return true;
62  }

◆ isSeekable()

GuzzleHttp\Psr7\BufferStream::isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 69 of file BufferStream.php.

70  {
71  return false;
72  }

◆ isWritable()

GuzzleHttp\Psr7\BufferStream::isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 64 of file BufferStream.php.

65  {
66  return true;
67  }

◆ read()

GuzzleHttp\Psr7\BufferStream::read (   $length)

Reads data from the buffer.

Implements Psr\Http\Message\StreamInterface.

Definition at line 97 of file BufferStream.php.

References GuzzleHttp\Psr7\BufferStream\$buffer, and $result.

98  {
99  $currentLength = strlen($this->buffer);
100 
101  if ($length >= $currentLength) {
102  // No need to slice the buffer because we don't have enough data.
104  $this->buffer = '';
105  } else {
106  // Slice up the result to provide a subset of the buffer.
107  $result = substr($this->buffer, 0, $length);
108  $this->buffer = substr($this->buffer, $length);
109  }
110 
111  return $result;
112  }
$result

◆ rewind()

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

References GuzzleHttp\Psr7\BufferStream\seek().

75  {
76  $this->seek(0);
77  }
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
+ Here is the call graph for this function:

◆ seek()

◆ tell()

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

90  {
91  throw new \RuntimeException('Cannot determine the position of a BufferStream');
92  }

◆ write()

GuzzleHttp\Psr7\BufferStream::write (   $string)

Writes data to the buffer.

Implements Psr\Http\Message\StreamInterface.

Definition at line 117 of file BufferStream.php.

118  {
119  $this->buffer .= $string;
120 
121  // TODO: What should happen here?
122  if (strlen($this->buffer) >= $this->hwm) {
123  return false;
124  }
125 
126  return strlen($string);
127  }

Field Documentation

◆ $buffer

GuzzleHttp\Psr7\BufferStream::$buffer = ''
private

◆ $hwm

GuzzleHttp\Psr7\BufferStream::$hwm
private

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