Phly\Http\Response\Serializer::fromStream PHP Метод

fromStream() публичный статический Метод

Parse a response from a stream.
public static fromStream ( Psr\Http\Message\StreamInterface $stream ) : Psr\Http\Message\ResponseInterface
$stream Psr\Http\Message\StreamInterface
Результат Psr\Http\Message\ResponseInterface
    public static function fromStream(StreamInterface $stream)
    {
        if (!$stream->isReadable() || !$stream->isSeekable()) {
            throw new InvalidArgumentException('Message stream must be both readable and seekable');
        }
        $stream->rewind();
        list($version, $status, $reasonPhrase) = self::getStatusLine($stream);
        list($headers, $body) = self::splitStream($stream);
        return (new Response($body, $status, $headers))->withProtocolVersion($version)->withStatus($status, $reasonPhrase);
    }

Usage Example

Пример #1
0
 public function testFromStreamThrowsExceptionWhenStreamIsNotSeekable()
 {
     $this->setExpectedException('InvalidArgumentException');
     $stream = $this->getMockBuilder('Psr\\Http\\Message\\StreamInterface')->getMock();
     $stream->expects($this->once())->method('isReadable')->will($this->returnValue(true));
     $stream->expects($this->once())->method('isSeekable')->will($this->returnValue(false));
     Serializer::fromStream($stream);
 }