コード例 #1
0
 /**
  * Read data from the stream.
  *
  * @param   int  $length  Read up to $length bytes from the object and return
  *                        them. Fewer than $length bytes may be returned if underlying stream
  *                        call returns fewer bytes.
  *
  * @return   string  Returns the data read from the stream, or an empty string
  *                   if no bytes are available.
  *
  * @throws \RuntimeException if an error occurs.
  */
 public function read($length)
 {
     $content = parent::read($length);
     if ($content && !static::$reachedEof) {
         static::$cache .= $content;
     }
     if ($this->eof()) {
         $this->reachedEof = true;
     }
     return $content;
 }
コード例 #2
0
 /**
  * Method to test read().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Stream::read
  */
 public function testRead()
 {
     $this->createTempFile();
     file_put_contents($this->tmpnam, 'FOO BAR');
     $resource = fopen($this->tmpnam, Stream::MODE_READ_ONLY_FROM_BEGIN);
     $stream = new Stream($resource);
     $this->assertEquals('FO', $stream->read(2));
     $this->assertEquals('O B', $stream->read(3));
     $stream->rewind();
     $this->assertEquals('FOO', $stream->read(3));
 }