PhpInputStream.php in Zircon Profile 8
File
vendor/zendframework/zend-diactoros/src/PhpInputStream.php
View source
<?php
namespace Zend\Diactoros;
class PhpInputStream extends Stream {
private $cache = '';
private $reachedEof = false;
public function __construct($stream = 'php://input', $mode = 'r') {
$mode = 'r';
parent::__construct($stream, $mode);
}
public function __toString() {
if ($this->reachedEof) {
return $this->cache;
}
$this
->getContents();
return $this->cache;
}
public function isWritable() {
return false;
}
public function read($length) {
$content = parent::read($length);
if ($content && !$this->reachedEof) {
$this->cache .= $content;
}
if ($this
->eof()) {
$this->reachedEof = true;
}
return $content;
}
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;
}
}