3 * Zend Framework (http://framework.zend.com/)
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
10 namespace Zend\Diactoros;
13 * Caching version of php://input
15 class PhpInputStream extends Stream
25 private $reachedEof = false;
28 * @param string|resource $stream
30 public function __construct($stream = 'php://input')
32 parent::__construct($stream, 'r');
38 public function __toString()
40 if ($this->reachedEof) {
51 public function isWritable()
59 public function read($length)
61 $content = parent::read($length);
62 if ($content && ! $this->reachedEof) {
63 $this->cache .= $content;
67 $this->reachedEof = true;
76 public function getContents($maxLength = -1)
78 if ($this->reachedEof) {
82 $contents = stream_get_contents($this->resource, $maxLength);
83 $this->cache .= $contents;
85 if ($maxLength === -1 || $this->eof()) {
86 $this->reachedEof = true;