Mercurial > hg > isophonics-drupal-site
diff vendor/zendframework/zend-diactoros/src/PhpInputStream.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/zendframework/zend-diactoros/src/PhpInputStream.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,91 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @see http://github.com/zendframework/zend-diactoros for the canonical source repository + * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License + */ + +namespace Zend\Diactoros; + +/** + * Caching version of php://input + */ +class PhpInputStream extends Stream +{ + /** + * @var string + */ + private $cache = ''; + + /** + * @var bool + */ + private $reachedEof = false; + + /** + * @param string|resource $stream + */ + public function __construct($stream = 'php://input') + { + parent::__construct($stream, 'r'); + } + + /** + * {@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 (! $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; + } +}