Mercurial > hg > isophonics-drupal-site
annotate vendor/zendframework/zend-diactoros/src/PhpInputStream.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | c2387f117808 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 /** |
Chris@12 | 3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
Chris@12 | 4 * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com) |
Chris@0 | 5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
Chris@0 | 6 */ |
Chris@0 | 7 |
Chris@0 | 8 namespace Zend\Diactoros; |
Chris@0 | 9 |
Chris@16 | 10 use function stream_get_contents; |
Chris@16 | 11 |
Chris@0 | 12 /** |
Chris@0 | 13 * Caching version of php://input |
Chris@0 | 14 */ |
Chris@0 | 15 class PhpInputStream extends Stream |
Chris@0 | 16 { |
Chris@0 | 17 /** |
Chris@0 | 18 * @var string |
Chris@0 | 19 */ |
Chris@0 | 20 private $cache = ''; |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * @var bool |
Chris@0 | 24 */ |
Chris@0 | 25 private $reachedEof = false; |
Chris@0 | 26 |
Chris@0 | 27 /** |
Chris@0 | 28 * @param string|resource $stream |
Chris@0 | 29 */ |
Chris@0 | 30 public function __construct($stream = 'php://input') |
Chris@0 | 31 { |
Chris@0 | 32 parent::__construct($stream, 'r'); |
Chris@0 | 33 } |
Chris@0 | 34 |
Chris@0 | 35 /** |
Chris@0 | 36 * {@inheritdoc} |
Chris@0 | 37 */ |
Chris@0 | 38 public function __toString() |
Chris@0 | 39 { |
Chris@0 | 40 if ($this->reachedEof) { |
Chris@0 | 41 return $this->cache; |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@0 | 44 $this->getContents(); |
Chris@0 | 45 return $this->cache; |
Chris@0 | 46 } |
Chris@0 | 47 |
Chris@0 | 48 /** |
Chris@0 | 49 * {@inheritdoc} |
Chris@0 | 50 */ |
Chris@0 | 51 public function isWritable() |
Chris@0 | 52 { |
Chris@0 | 53 return false; |
Chris@0 | 54 } |
Chris@0 | 55 |
Chris@0 | 56 /** |
Chris@0 | 57 * {@inheritdoc} |
Chris@0 | 58 */ |
Chris@0 | 59 public function read($length) |
Chris@0 | 60 { |
Chris@0 | 61 $content = parent::read($length); |
Chris@0 | 62 if (! $this->reachedEof) { |
Chris@0 | 63 $this->cache .= $content; |
Chris@0 | 64 } |
Chris@0 | 65 |
Chris@0 | 66 if ($this->eof()) { |
Chris@0 | 67 $this->reachedEof = true; |
Chris@0 | 68 } |
Chris@0 | 69 |
Chris@0 | 70 return $content; |
Chris@0 | 71 } |
Chris@0 | 72 |
Chris@0 | 73 /** |
Chris@0 | 74 * {@inheritdoc} |
Chris@0 | 75 */ |
Chris@0 | 76 public function getContents($maxLength = -1) |
Chris@0 | 77 { |
Chris@0 | 78 if ($this->reachedEof) { |
Chris@0 | 79 return $this->cache; |
Chris@0 | 80 } |
Chris@0 | 81 |
Chris@0 | 82 $contents = stream_get_contents($this->resource, $maxLength); |
Chris@0 | 83 $this->cache .= $contents; |
Chris@0 | 84 |
Chris@0 | 85 if ($maxLength === -1 || $this->eof()) { |
Chris@0 | 86 $this->reachedEof = true; |
Chris@0 | 87 } |
Chris@0 | 88 |
Chris@0 | 89 return $contents; |
Chris@0 | 90 } |
Chris@0 | 91 } |