[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @see https://github.com/laminas/laminas-diactoros for the canonical source repository 5 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md 6 * @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License 7 */ 8 9 declare(strict_types=1); 10 11 namespace Laminas\Diactoros; 12 13 use function stream_get_contents; 14 15 /** 16 * Caching version of php://input 17 */ 18 class PhpInputStream extends Stream 19 { 20 /** 21 * @var string 22 */ 23 private $cache = ''; 24 25 /** 26 * @var bool 27 */ 28 private $reachedEof = false; 29 30 /** 31 * @param string|resource $stream 32 */ 33 public function __construct($stream = 'php://input') 34 { 35 parent::__construct($stream, 'r'); 36 } 37 38 /** 39 * {@inheritdoc} 40 */ 41 public function __toString() : string 42 { 43 if ($this->reachedEof) { 44 return $this->cache; 45 } 46 47 $this->getContents(); 48 return $this->cache; 49 } 50 51 /** 52 * {@inheritdoc} 53 */ 54 public function isWritable() : bool 55 { 56 return false; 57 } 58 59 /** 60 * {@inheritdoc} 61 */ 62 public function read($length) : string 63 { 64 $content = parent::read($length); 65 if (! $this->reachedEof) { 66 $this->cache .= $content; 67 } 68 69 if ($this->eof()) { 70 $this->reachedEof = true; 71 } 72 73 return $content; 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 public function getContents($maxLength = -1) : string 80 { 81 if ($this->reachedEof) { 82 return $this->cache; 83 } 84 85 $contents = stream_get_contents($this->resource, $maxLength); 86 $this->cache .= $contents; 87 88 if ($maxLength === -1 || $this->eof()) { 89 $this->reachedEof = true; 90 } 91 92 return $contents; 93 } 94 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |