You are here

public static function Serializer::fromStream in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/zendframework/zend-diactoros/src/Request/Serializer.php \Zend\Diactoros\Request\Serializer::fromStream()
  2. 8.0 vendor/zendframework/zend-diactoros/src/Response/Serializer.php \Zend\Diactoros\Response\Serializer::fromStream()
Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-diactoros/src/Request/Serializer.php \Zend\Diactoros\Request\Serializer::fromStream()

Deserialize a request stream to a request instance.

Parameters

StreamInterface $stream:

Return value

Request

Throws

UnexpectedValueException when errors occur parsing the message.

1 call to Serializer::fromStream()
Serializer::fromString in vendor/zendframework/zend-diactoros/src/Request/Serializer.php
Deserialize a request string to a request instance.

File

vendor/zendframework/zend-diactoros/src/Request/Serializer.php, line 53

Class

Serializer
Serialize (cast to string) or deserialize (cast string to Request) messages.

Namespace

Zend\Diactoros\Request

Code

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($method, $requestTarget, $version) = self::getRequestLine($stream);
  $uri = self::createUriFromRequestTarget($requestTarget);
  list($headers, $body) = self::splitStream($stream);
  return (new Request($uri, $method, $body, $headers))
    ->withProtocolVersion($version)
    ->withRequestTarget($requestTarget);
}