3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4 * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
8 namespace Zend\Diactoros;
11 * Caching version of php://input
13 class PhpInputStream extends Stream
23 private $reachedEof = false;
26 * @param string|resource $stream
28 public function __construct($stream = 'php://input')
30 parent::__construct($stream, 'r');
36 public function __toString()
38 if ($this->reachedEof) {
49 public function isWritable()
57 public function read($length)
59 $content = parent::read($length);
60 if (! $this->reachedEof) {
61 $this->cache .= $content;
65 $this->reachedEof = true;
74 public function getContents($maxLength = -1)
76 if ($this->reachedEof) {
80 $contents = stream_get_contents($this->resource, $maxLength);
81 $this->cache .= $contents;
83 if ($maxLength === -1 || $this->eof()) {
84 $this->reachedEof = true;