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

Provides a read only stream that pumps data from a PHP callable. More...

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

Public Member Functions

 __construct (callable $source, array $options=[])
 
 __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...
 
 rewind ()
 Seek to the beginning of the stream. More...
 
 seek ($offset, $whence=SEEK_SET)
 Seek to a position in the stream. More...
 
 isWritable ()
 Returns whether or not the stream is writable. More...
 
 write ($string)
 Write data to the stream. 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 Member Functions

 pump ($length)
 

Private Attributes

 $source
 
 $size
 
 $tellPos = 0
 
 $metadata
 
 $buffer
 

Detailed Description

Provides a read only stream that pumps data from a PHP callable.

When invoking the provided callable, the PumpStream will pass the amount of data requested to read to the callable. The callable can choose to ignore this value and return fewer or more bytes than requested. Any extra data returned by the provided callable is buffered internally until drained using the read() function of the PumpStream. The provided callable MUST return false when there is no more data to read.

Definition at line 16 of file PumpStream.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\PumpStream::__construct ( callable  $source,
array  $options = [] 
)
Parameters
callable$sourceSource of the stream data. The callable MAY accept an integer argument used to control the amount of data to return. The callable MUST return a string when called, or false on error or EOF.
array$optionsStream options:
  • metadata: Hash of metadata to use with stream.
  • size: Size of the stream, if known.

Definition at line 43 of file PumpStream.php.

References $options, GuzzleHttp\Psr7\PumpStream\$source, and size.

44  {
45  $this->source = $source;
46  $this->size = isset($options['size']) ? $options['size'] : null;
47  $this->metadata = isset($options['metadata']) ? $options['metadata'] : [];
48  $this->buffer = new BufferStream();
49  }
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Set page orientation and size
Definition: 04printing.php:77

Member Function Documentation

◆ __toString()

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

References GuzzleHttp\Psr7\copy_to_string().

52  {
53  try {
54  return copy_to_string($this);
55  } catch (\Exception $e) {
56  return '';
57  }
58  }
copy_to_string(StreamInterface $stream, $maxLen=-1)
Copy the contents of a stream into a string until the given number of bytes have been read...
Definition: functions.php:328
+ Here is the call graph for this function:

◆ close()

GuzzleHttp\Psr7\PumpStream::close ( )

Closes the stream and any underlying resources.

Returns
void

Implements Psr\Http\Message\StreamInterface.

Definition at line 60 of file PumpStream.php.

References GuzzleHttp\Psr7\PumpStream\detach().

61  {
62  $this->detach();
63  }
detach()
Separates any underlying resources from the stream.
Definition: PumpStream.php:65
+ Here is the call graph for this function:

◆ detach()

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

Referenced by GuzzleHttp\Psr7\PumpStream\close().

66  {
67  $this->tellPos = false;
68  $this->source = null;
69  }
+ Here is the caller graph for this function:

◆ eof()

GuzzleHttp\Psr7\PumpStream::eof ( )

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

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 81 of file PumpStream.php.

References GuzzleHttp\Psr7\PumpStream\$source.

Referenced by GuzzleHttp\Psr7\PumpStream\getContents().

82  {
83  return !$this->source;
84  }
+ Here is the caller graph for this function:

◆ getContents()

GuzzleHttp\Psr7\PumpStream::getContents ( )

Returns the remaining contents in a string.

Returns
string
Exceptions

Implements Psr\Http\Message\StreamInterface.

Definition at line 132 of file PumpStream.php.

References $result, GuzzleHttp\Psr7\PumpStream\eof(), and GuzzleHttp\Psr7\PumpStream\read().

133  {
134  $result = '';
135  while (!$this->eof()) {
136  $result .= $this->read(1000000);
137  }
138 
139  return $result;
140  }
$result
read($length)
Read data from the stream.
Definition: PumpStream.php:116
eof()
Returns true if the stream is at the end of the stream.
Definition: PumpStream.php:81
+ Here is the call graph for this function:

◆ getMetadata()

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

References $key, and GuzzleHttp\Psr7\PumpStream\$metadata.

143  {
144  if (!$key) {
145  return $this->metadata;
146  }
147 
148  return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
149  }
$key
Definition: croninfo.php:18

◆ getSize()

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

References GuzzleHttp\Psr7\PumpStream\$size.

72  {
73  return $this->size;
74  }

◆ isReadable()

GuzzleHttp\Psr7\PumpStream::isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 111 of file PumpStream.php.

112  {
113  return true;
114  }

◆ isSeekable()

GuzzleHttp\Psr7\PumpStream::isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 86 of file PumpStream.php.

87  {
88  return false;
89  }

◆ isWritable()

GuzzleHttp\Psr7\PumpStream::isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 101 of file PumpStream.php.

102  {
103  return false;
104  }

◆ pump()

GuzzleHttp\Psr7\PumpStream::pump (   $length)
private

Definition at line 151 of file PumpStream.php.

References $data.

Referenced by GuzzleHttp\Psr7\PumpStream\read().

152  {
153  if ($this->source) {
154  do {
155  $data = call_user_func($this->source, $length);
156  if ($data === false || $data === null) {
157  $this->source = null;
158  return;
159  }
160  $this->buffer->write($data);
161  $length -= strlen($data);
162  } while ($length > 0);
163  }
164  }
+ Here is the caller graph for this function:

◆ read()

GuzzleHttp\Psr7\PumpStream::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

Implements Psr\Http\Message\StreamInterface.

Definition at line 116 of file PumpStream.php.

References $data, $remaining, and GuzzleHttp\Psr7\PumpStream\pump().

Referenced by GuzzleHttp\Psr7\PumpStream\getContents().

117  {
118  $data = $this->buffer->read($length);
119  $readLen = strlen($data);
120  $this->tellPos += $readLen;
121  $remaining = $length - $readLen;
122 
123  if ($remaining) {
124  $this->pump($remaining);
125  $data .= $this->buffer->read($remaining);
126  $this->tellPos += strlen($data) - $readLen;
127  }
128 
129  return $data;
130  }
if($state['core:TerminatedAssocId'] !==null) $remaining
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rewind()

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

References GuzzleHttp\Psr7\PumpStream\seek().

92  {
93  $this->seek(0);
94  }
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
Definition: PumpStream.php:96
+ Here is the call graph for this function:

◆ seek()

◆ tell()

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

References GuzzleHttp\Psr7\PumpStream\$tellPos.

77  {
78  return $this->tellPos;
79  }

◆ write()

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

107  {
108  throw new \RuntimeException('Cannot write to a PumpStream');
109  }

Field Documentation

◆ $buffer

GuzzleHttp\Psr7\PumpStream::$buffer
private

Definition at line 31 of file PumpStream.php.

◆ $metadata

GuzzleHttp\Psr7\PumpStream::$metadata
private

Definition at line 28 of file PumpStream.php.

Referenced by GuzzleHttp\Psr7\PumpStream\getMetadata().

◆ $size

GuzzleHttp\Psr7\PumpStream::$size
private

Definition at line 22 of file PumpStream.php.

Referenced by GuzzleHttp\Psr7\PumpStream\getSize().

◆ $source

GuzzleHttp\Psr7\PumpStream::$source
private

◆ $tellPos

GuzzleHttp\Psr7\PumpStream::$tellPos = 0
private

Definition at line 25 of file PumpStream.php.

Referenced by GuzzleHttp\Psr7\PumpStream\tell().


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