You are here

class PhpInputStream in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/PhpInputStream.php \Zend\Diactoros\PhpInputStream

Caching version of php://input

Hierarchy

Expanded class hierarchy of PhpInputStream

File

vendor/zendframework/zend-diactoros/src/PhpInputStream.php, line 15

Namespace

Zend\Diactoros
View source
class PhpInputStream extends Stream {

  /**
   * @var string
   */
  private $cache = '';

  /**
   * @var bool
   */
  private $reachedEof = false;

  /**
   * @param  string|resource $stream
   * @param  string $mode
   */
  public function __construct($stream = 'php://input', $mode = 'r') {
    $mode = 'r';
    parent::__construct($stream, $mode);
  }

  /**
   * {@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 ($content && !$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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpInputStream::$cache private property
PhpInputStream::$reachedEof private property
PhpInputStream::getContents public function Returns the remaining contents in a string Overrides Stream::getContents
PhpInputStream::isWritable public function Returns whether or not the stream is writable. Overrides Stream::isWritable
PhpInputStream::read public function Read data from the stream. Overrides Stream::read
PhpInputStream::__construct public function Overrides Stream::__construct
PhpInputStream::__toString public function Reads all data from the stream into a string, from the beginning to end. Overrides Stream::__toString
Stream::$resource protected property
Stream::$stream protected property
Stream::attach public function Attach a new stream/resource to the instance.
Stream::close public function Closes the stream and any underlying resources. Overrides StreamInterface::close
Stream::detach public function Separates any underlying resources from the stream. Overrides StreamInterface::detach
Stream::eof public function Returns true if the stream is at the end of the stream. Overrides StreamInterface::eof
Stream::getMetadata public function Get stream metadata as an associative array or retrieve a specific key. Overrides StreamInterface::getMetadata
Stream::getSize public function Get the size of the stream if known. Overrides StreamInterface::getSize
Stream::isReadable public function Returns whether or not the stream is readable. Overrides StreamInterface::isReadable
Stream::isSeekable public function Returns whether or not the stream is seekable. Overrides StreamInterface::isSeekable
Stream::rewind public function Seek to the beginning of the stream. Overrides StreamInterface::rewind
Stream::seek public function Seek to a position in the stream. Overrides StreamInterface::seek
Stream::setStream private function Set the internal stream resource.
Stream::tell public function Returns the current position of the file read/write pointer Overrides StreamInterface::tell
Stream::write public function Write data to the stream. Overrides StreamInterface::write