class PhpInputStream in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-diactoros/src/PhpInputStream.php \Zend\Diactoros\PhpInputStream
Caching version of php://input
Hierarchy
- class \Zend\Diactoros\Stream implements StreamInterface
- class \Zend\Diactoros\PhpInputStream
Expanded class hierarchy of PhpInputStream
File
- vendor/
zendframework/ zend-diactoros/ src/ PhpInputStream.php, line 15
Namespace
Zend\DiactorosView source
class PhpInputStream extends Stream {
/**
* @var string
*/
private $cache = '';
/**
* @var bool
*/
private $reachedEof = false;
/**
* @param string|resource $stream
* @param string $mode
*/
public function __construct($stream = 'php://input', $mode = 'r') {
$mode = 'r';
parent::__construct($stream, $mode);
}
/**
* {@inheritdoc}
*/
public function __toString() {
if ($this->reachedEof) {
return $this->cache;
}
$this
->getContents();
return $this->cache;
}
/**
* {@inheritdoc}
*/
public function isWritable() {
return false;
}
/**
* {@inheritdoc}
*/
public function read($length) {
$content = parent::read($length);
if ($content && !$this->reachedEof) {
$this->cache .= $content;
}
if ($this
->eof()) {
$this->reachedEof = true;
}
return $content;
}
/**
* {@inheritdoc}
*/
public function getContents($maxLength = -1) {
if ($this->reachedEof) {
return $this->cache;
}
$contents = stream_get_contents($this->resource, $maxLength);
$this->cache .= $contents;
if ($maxLength === -1 || $this
->eof()) {
$this->reachedEof = true;
}
return $contents;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpInputStream:: |
private | property | ||
PhpInputStream:: |
private | property | ||
PhpInputStream:: |
public | function |
Returns the remaining contents in a string Overrides Stream:: |
|
PhpInputStream:: |
public | function |
Returns whether or not the stream is writable. Overrides Stream:: |
|
PhpInputStream:: |
public | function |
Read data from the stream. Overrides Stream:: |
|
PhpInputStream:: |
public | function |
Overrides Stream:: |
|
PhpInputStream:: |
public | function |
Reads all data from the stream into a string, from the beginning to end. Overrides Stream:: |
|
Stream:: |
protected | property | ||
Stream:: |
protected | property | ||
Stream:: |
public | function | Attach a new stream/resource to the instance. | |
Stream:: |
public | function |
Closes the stream and any underlying resources. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Separates any underlying resources from the stream. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Returns true if the stream is at the end of the stream. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Get stream metadata as an associative array or retrieve a specific key. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Get the size of the stream if known. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Returns whether or not the stream is readable. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Returns whether or not the stream is seekable. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Seek to the beginning of the stream. Overrides StreamInterface:: |
|
Stream:: |
public | function |
Seek to a position in the stream. Overrides StreamInterface:: |
|
Stream:: |
private | function | Set the internal stream resource. | |
Stream:: |
public | function |
Returns the current position of the file read/write pointer Overrides StreamInterface:: |
|
Stream:: |
public | function |
Write data to the stream. Overrides StreamInterface:: |