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

Compose stream implementations based on a hash of functions. More...

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

Public Member Functions

 __construct (array $methods)
 
 __get ($name)
 Lazily determine which methods are not implemented. More...
 
 __destruct ()
 The close method is called on the underlying stream only if possible. More...
 
 __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...
 

Static Public Member Functions

static decorate (StreamInterface $stream, array $methods)
 Adds custom functionality to an underlying stream by intercepting specific method calls. More...
 

Private Attributes

 $methods
 

Static Private Attributes

static $slots
 

Detailed Description

Compose stream implementations based on a hash of functions.

Allows for easy testing and extension of a provided stream without needing to create a concrete class for a simple extension point.

Definition at line 12 of file FnStream.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\FnStream::__construct ( array  $methods)
Parameters
array$methodsHash of method name to a callable.

Definition at line 25 of file FnStream.php.

References GuzzleHttp\Psr7\FnStream\$methods, and $name.

26  {
27  $this->methods = $methods;
28 
29  // Create the functions on the class
30  foreach ($methods as $name => $fn) {
31  $this->{'_fn_' . $name} = $fn;
32  }
33  }

◆ __destruct()

GuzzleHttp\Psr7\FnStream::__destruct ( )

The close method is called on the underlying stream only if possible.

Definition at line 48 of file FnStream.php.

49  {
50  if (isset($this->_fn_close)) {
51  call_user_func($this->_fn_close);
52  }
53  }

Member Function Documentation

◆ __get()

GuzzleHttp\Psr7\FnStream::__get (   $name)

Lazily determine which methods are not implemented.

Exceptions

Definition at line 39 of file FnStream.php.

References $name.

40  {
41  throw new \BadMethodCallException(str_replace('_fn_', '', $name)
42  . '() is not implemented in the FnStream');
43  }

◆ __toString()

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

76  {
77  return call_user_func($this->_fn___toString);
78  }

◆ close()

GuzzleHttp\Psr7\FnStream::close ( )

Closes the stream and any underlying resources.

Returns
void

Implements Psr\Http\Message\StreamInterface.

Definition at line 80 of file FnStream.php.

81  {
82  return call_user_func($this->_fn_close);
83  }

◆ decorate()

static GuzzleHttp\Psr7\FnStream::decorate ( StreamInterface  $stream,
array  $methods 
)
static

Adds custom functionality to an underlying stream by intercepting specific method calls.

Parameters
StreamInterface$streamStream to decorate
array$methodsHash of method name to a closure
Returns
FnStream

Definition at line 64 of file FnStream.php.

References GuzzleHttp\Psr7\FnStream\$methods, and GuzzleHttp\Psr7\$stream.

65  {
66  // If any of the required methods were not provided, then simply
67  // proxy to the decorated stream.
68  foreach (array_diff(self::$slots, array_keys($methods)) as $diff) {
69  $methods[$diff] = [$stream, $diff];
70  }
71 
72  return new self($methods);
73  }
$stream
PHP stream implementation.

◆ detach()

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

86  {
87  return call_user_func($this->_fn_detach);
88  }

◆ eof()

GuzzleHttp\Psr7\FnStream::eof ( )

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

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 100 of file FnStream.php.

101  {
102  return call_user_func($this->_fn_eof);
103  }

◆ getContents()

GuzzleHttp\Psr7\FnStream::getContents ( )

Returns the remaining contents in a string.

Returns
string
Exceptions

Implements Psr\Http\Message\StreamInterface.

Definition at line 140 of file FnStream.php.

141  {
142  return call_user_func($this->_fn_getContents);
143  }

◆ getMetadata()

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

References $key.

146  {
147  return call_user_func($this->_fn_getMetadata, $key);
148  }
$key
Definition: croninfo.php:18

◆ getSize()

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

91  {
92  return call_user_func($this->_fn_getSize);
93  }

◆ isReadable()

GuzzleHttp\Psr7\FnStream::isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 130 of file FnStream.php.

131  {
132  return call_user_func($this->_fn_isReadable);
133  }

◆ isSeekable()

GuzzleHttp\Psr7\FnStream::isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 105 of file FnStream.php.

106  {
107  return call_user_func($this->_fn_isSeekable);
108  }

◆ isWritable()

GuzzleHttp\Psr7\FnStream::isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 120 of file FnStream.php.

121  {
122  return call_user_func($this->_fn_isWritable);
123  }

◆ read()

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

136  {
137  return call_user_func($this->_fn_read, $length);
138  }

◆ rewind()

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

111  {
112  call_user_func($this->_fn_rewind);
113  }

◆ seek()

◆ tell()

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

96  {
97  return call_user_func($this->_fn_tell);
98  }

◆ write()

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

126  {
127  return call_user_func($this->_fn_write, $string);
128  }

Field Documentation

◆ $methods

GuzzleHttp\Psr7\FnStream::$methods
private

◆ $slots

GuzzleHttp\Psr7\FnStream::$slots
staticprivate
Initial value:
= ['__toString', 'close', 'detach', 'rewind',
'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
'isReadable', 'read', 'getContents', 'getMetadata']

Definition at line 18 of file FnStream.php.


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