\Zend\Diactoros\ResponseSerializer

Provides base functionality for request and response de/serialization strategies, including functionality for retrieving a line at a time from the message, splitting headers from the body, and serializing headers.

Summary

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

Constants

CR

CR = "\r"

EOL

EOL = "\r\n"

LF

LF = "\n"

Methods

fromString()

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

Deserialize a response string to a response instance.

Parameters

string $message

Throws

\UnexpectedValueException

when errors occur parsing the message.

Returns

\Zend\Diactoros\Response

fromStream()

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

Parse a response from a stream.

Parameters

\Psr\Http\Message\StreamInterface $stream

Throws

\InvalidArgumentException

when the stream is not readable.

\UnexpectedValueException

when errors occur parsing the message.

Returns

\Zend\Diactoros\Response

toString()

toString(\Psr\Http\Message\ResponseInterface  $response) : string

Create a string representation of a response.

Parameters

\Psr\Http\Message\ResponseInterface $response

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

getStatusLine()

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

Retrieve the status line for the message.

Parameters

\Psr\Http\Message\StreamInterface $stream

Throws

\UnexpectedValueException

if line is malformed

Returns

array —

Array with three elements: 0 => version, 1 => status, 2 => reason