ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ZipStream\Stream Class Reference

Describes a data stream. More...

+ Inheritance diagram for ZipStream\Stream:
+ Collaboration diagram for ZipStream\Stream:

Public Member Functions

 __construct ($stream)
 
 close ()
 Closes the stream and any underlying resources. More...
 
 detach ()
 Separates any underlying resources from the stream. More...
 
 __toString ()
 Reads all data from the stream into a string, from the beginning to end. More...
 
 seek ($offset, $whence=SEEK_SET)
 Seek to a position in the stream. More...
 
 isSeekable ()
 Returns whether or not the stream is seekable. More...
 
 getMetadata ($key=null)
 Get stream metadata as an associative array or retrieve a specific key. 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...
 
 rewind ()
 Seek to the beginning of the stream. More...
 
 write ($string)
 Write data to the stream. More...
 
 isWritable ()
 Returns whether or not the stream is writable. More...
 
 read ($length)
 Read data from the stream. More...
 
 isReadable ()
 Returns whether or not the stream is readable. More...
 
 getContents ()
 Returns the remaining contents in a string. More...
 

Protected Attributes

 $stream
 

Detailed Description

Describes a data stream.

Typically, an instance will wrap a PHP stream; this interface provides a wrapper around the most common operations, including serialization of the entire stream to a string.

Definition at line 16 of file Stream.php.

Constructor & Destructor Documentation

◆ __construct()

ZipStream\Stream::__construct (   $stream)

Definition at line 20 of file Stream.php.

References GuzzleHttp\Psr7\$stream.

21  {
22  $this->stream = $stream;
23  }

Member Function Documentation

◆ __toString()

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

Implements Psr\Http\Message\StreamInterface.

Definition at line 66 of file Stream.php.

66  : string
67  {
68  try {
69  $this->seek(0);
70  } catch (\RuntimeException $e) {}
71  return (string) stream_get_contents($this->stream);
72  }
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
Definition: Stream.php:86

◆ close()

ZipStream\Stream::close ( )

Closes the stream and any underlying resources.

Returns
void

Implements Psr\Http\Message\StreamInterface.

Definition at line 30 of file Stream.php.

30  : void
31  {
32  if (is_resource($this->stream)) {
33  fclose($this->stream);
34  }
35  $this->detach();
36  }
detach()
Separates any underlying resources from the stream.
Definition: Stream.php:45

◆ detach()

ZipStream\Stream::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 45 of file Stream.php.

References $result, and GuzzleHttp\Psr7\$stream.

46  {
48  $this->stream = null;
49  return $result;
50  }
$result

◆ eof()

ZipStream\Stream::eof ( )

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

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 155 of file Stream.php.

155  : bool
156  {
157  return feof($this->stream);
158  }

◆ getContents()

ZipStream\Stream::getContents ( )

Returns the remaining contents in a string.

Returns
string
Exceptions

Implements Psr\Http\Message\StreamInterface.

Definition at line 242 of file Stream.php.

References $result.

242  : string
243  {
244  if (!$this->isReadable()) {
245  throw new RuntimeException;
246  }
247  $result = stream_get_contents($this->stream);
248  if ($result === false) {
249  throw new RuntimeException;
250  }
251  return $result;
252  }
$result
isReadable()
Returns whether or not the stream is readable.
Definition: Stream.php:230

◆ getMetadata()

ZipStream\Stream::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 118 of file Stream.php.

References $key, and $metadata.

119  {
120  $metadata = stream_get_meta_data($this->stream);
121  return $key !== null ? @$metadata[$key] : $metadata;
122  }
$metadata['__DYNAMIC:1__']
$key
Definition: croninfo.php:18

◆ getSize()

ZipStream\Stream::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 129 of file Stream.php.

References Sabre\VObject\$stats.

129  : ?int
130  {
131  $stats = fstat($this->stream);
132  return $stats['size'];
133  }

◆ isReadable()

ZipStream\Stream::isReadable ( )

Returns whether or not the stream is readable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 230 of file Stream.php.

230  : bool
231  {
232  return preg_match('/[r+]/', $this->getMetadata('mode')) === 1;
233  }
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
Definition: Stream.php:118

◆ isSeekable()

ZipStream\Stream::isSeekable ( )

Returns whether or not the stream is seekable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 101 of file Stream.php.

101  : bool
102  {
103  return (bool)$this->getMetadata('seekable');
104  }
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
Definition: Stream.php:118

◆ isWritable()

ZipStream\Stream::isWritable ( )

Returns whether or not the stream is writable.

Returns
bool

Implements Psr\Http\Message\StreamInterface.

Definition at line 198 of file Stream.php.

198  : bool
199  {
200  return preg_match('/[waxc+]/', $this->getMetadata('mode')) === 1;
201  }
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
Definition: Stream.php:118

◆ read()

ZipStream\Stream::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 213 of file Stream.php.

References $result.

213  : string
214  {
215  if (!$this->isReadable()) {
216  throw new RuntimeException;
217  }
218  $result = fread($this->stream, $length);
219  if ($result === false) {
220  throw new RuntimeException;
221  }
222  return $result;
223  }
$result
isReadable()
Returns whether or not the stream is readable.
Definition: Stream.php:230

◆ rewind()

ZipStream\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.

Implements Psr\Http\Message\StreamInterface.

Definition at line 170 of file Stream.php.

170  : void
171  {
172  $this->seek(0);
173  }
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
Definition: Stream.php:86

◆ seek()

ZipStream\Stream::seek (   $offset,
  $whence = SEEK_SET 
)

◆ tell()

ZipStream\Stream::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 141 of file Stream.php.

141  : int
142  {
143  $position = ftell($this->stream);
144  if ($position === false) {
145  throw new RuntimeException;
146  }
147  return $position;
148  }

◆ write()

ZipStream\Stream::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 182 of file Stream.php.

182  : int
183  {
184  if (!$this->isWritable()) {
185  throw new RuntimeException;
186  }
187  if (fwrite($this->stream, $string) === false) {
188  throw new RuntimeException;
189  }
190  return \mb_strlen($string);
191  }
isWritable()
Returns whether or not the stream is writable.
Definition: Stream.php:198

Field Documentation

◆ $stream

ZipStream\Stream::$stream
protected

Definition at line 18 of file Stream.php.


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