Phly\Http\Stream::read PHP Method

read() public method

public read ( $length )
    public function read($length)
    {
        if (!$this->resource) {
            throw new RuntimeException('No resource available; cannot read');
        }
        if (!$this->isReadable()) {
            throw new RuntimeException('Stream is not readable');
        }
        $result = fread($this->resource, $length);
        if (false === $result) {
            throw new RuntimeException('Error reading stream');
        }
        return $result;
    }

Usage Example

Beispiel #1
0
 public function testReadReturnsEmptyStringWhenAtEndOfFile()
 {
     $this->tmpnam = tempnam(sys_get_temp_dir(), 'phly');
     file_put_contents($this->tmpnam, 'FOO BAR');
     $resource = fopen($this->tmpnam, 'r');
     $stream = new Stream($resource);
     while (!feof($resource)) {
         fread($resource, 4096);
     }
     $this->assertEquals('', $stream->read(4096));
 }