Serializer
extends AbstractSerializer
in package
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
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
CR
public
mixed
CR
= "\r"
EOL
public
mixed
EOL
= "\r\n"
LF
public
mixed
LF
= "\n"
Methods
fromStream()
Deserialize a request stream to a request instance.
public
static fromStream(StreamInterface $stream) : Request
Parameters
- $stream : StreamInterface
Tags
Return values
RequestfromString()
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
Return values
RequesttoString()
Serialize a request message to a string.
public
static toString(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringfilterHeader()
Filter a header name to wordcase
protected
static filterHeader(string $header) : string
Parameters
- $header : string
Return values
stringgetLine()
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
Return values
stringserializeHeaders()
Serialize headers to string values.
protected
static serializeHeaders(array<string|int, mixed> $headers) : string
Parameters
- $headers : array<string|int, mixed>
Tags
Return values
stringsplitStream()
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
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
UrigetRequestLine()
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