Fr3nch13/CakePHP Utilities

Serializer extends AbstractSerializer
in package

FinalYes

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.

Table of Contents

Constants

CR  = "\r"
EOL  = "\r\n"
LF  = "\n"

Methods

fromStream()  : Request
Deserialize a request stream to a request instance.
fromString()  : Request
Deserialize a request string to a request instance.
toString()  : string
Serialize a request message to a string.
filterHeader()  : string
Filter a header name to wordcase
getLine()  : string
Retrieve a single line from the stream.
serializeHeaders()  : string
Serialize headers to string values.
splitStream()  : array<string|int, mixed>
Split the stream into headers and body content.
createUriFromRequestTarget()  : Uri
Create and return a Uri instance based on the provided request target.
getRequestLine()  : array<string|int, mixed>
Retrieve the components of the request line.

Constants

Methods

fromString()

Deserialize a request string to a request instance.

public static fromString(string $message) : Request

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

Parameters
$message : string
Tags
throws
SerializationException

When errors occur parsing the message.

Return values
Request

filterHeader()

Filter a header name to wordcase

protected static filterHeader(string $header) : string
Parameters
$header : string
Return values
string

getLine()

Retrieve a single line from the stream.

protected static getLine(StreamInterface $stream) : string

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

Parameters
$stream : StreamInterface
Tags
throws
DeserializationException

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

Return values
string

serializeHeaders()

Serialize headers to string values.

protected static serializeHeaders(array<string|int, mixed> $headers) : string
Parameters
$headers : array<string|int, mixed>
Tags
psalm-param

array<string, string[]> $headers

Return values
string

splitStream()

Split the stream into headers and body content.

protected static splitStream(StreamInterface $stream) : array<string|int, mixed>

Returns an array containing two elements

  • The first is an array of headers
  • The second is a StreamInterface containing the body content
Parameters
$stream : StreamInterface
Tags
throws
DeserializationException

For invalid headers.

Return values
array<string|int, mixed>

createUriFromRequestTarget()

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

private static createUriFromRequestTarget(string $requestTarget) : Uri

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
$requestTarget : string
Return values
Uri

getRequestLine()

Retrieve the components of the request line.

private static getRequestLine(StreamInterface $stream) : array<string|int, mixed>

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
$stream : StreamInterface
Tags
throws
SerializationException
Return values
array<string|int, mixed>

        
On this page

Search results