\Zend\Diactoros\RequestSerializer

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

This class provides functionality for serializing a RequestInterface instance to a string, as well as the reverse operation of creating a Request instance from a string/stream representing a message.

Summary

Methods
Properties
Constants
fromString()
fromStream()
toString()
No public properties found
CR
EOL
LF
getLine()
splitStream()
serializeHeaders()
filterHeader()
No protected properties found
N/A
getRequestLine()
createUriFromRequestTarget()
No private properties found
N/A

Constants

CR

CR = "\r"

EOL

EOL = "\r\n"

LF

LF = "\n"

Methods

fromString()

fromString(string  $message) : \Zend\Diactoros\Request

Deserialize a request string to a request instance.

Internally, casts the message to a stream and invokes fromStream().

Parameters

string $message

Throws

\UnexpectedValueException

when errors occur parsing the message.

Returns

\Zend\Diactoros\Request

fromStream()

fromStream(\Psr\Http\Message\StreamInterface  $stream) : \Zend\Diactoros\Request

Deserialize a request stream to a request instance.

Parameters

\Psr\Http\Message\StreamInterface $stream

Throws

\UnexpectedValueException

when errors occur parsing the message.

Returns

\Zend\Diactoros\Request

toString()

toString(\Psr\Http\Message\RequestInterface  $request) : string

Serialize a request message to a string.

Parameters

\Psr\Http\Message\RequestInterface $request

Returns

string

getLine()

getLine(\Psr\Http\Message\StreamInterface  $stream) : string

Retrieve a single line from the stream.

Retrieves a line from the stream; a line is defined as a sequence of characters ending in a CRLF sequence.

Parameters

\Psr\Http\Message\StreamInterface $stream

Throws

\UnexpectedValueException

if the sequence contains a CR or LF in isolation, or ends in a CR.

Returns

string

splitStream()

splitStream(\Psr\Http\Message\StreamInterface  $stream) : array

Split the stream into headers and body content.

Returns an array containing two elements

  • The first is an array of headers
  • The second is a StreamInterface containing the body content

Parameters

\Psr\Http\Message\StreamInterface $stream

Throws

\UnexpectedValueException

For invalid headers.

Returns

array

serializeHeaders()

serializeHeaders(array  $headers) : string

Serialize headers to string values.

Parameters

array $headers

Returns

string

filterHeader()

filterHeader(string  $header) : string

Filter a header name to wordcase

Parameters

string $header

Returns

string

getRequestLine()

getRequestLine(\Psr\Http\Message\StreamInterface  $stream) : array

Retrieve the components of the request line.

Retrieves the first line of the stream and parses it, raising an exception if it does not follow specifications; if valid, returns a list with the method, target, and version, in that order.

Parameters

\Psr\Http\Message\StreamInterface $stream

Returns

array

createUriFromRequestTarget()

createUriFromRequestTarget(string  $requestTarget) : \Zend\Diactoros\Uri

Create and return a Uri instance based on the provided request target.

If the request target is of authority or asterisk form, an empty Uri instance is returned; otherwise, the value is used to create and return a new Uri instance.

Parameters

string $requestTarget

Returns

\Zend\Diactoros\Uri