TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Message Class Reference
Inheritance diagram for Message:
Request Response ServerRequest

Public Member Functions

 getProtocolVersion ()
 
 withProtocolVersion ($version)
 
 getHeaders ()
 
 hasHeader ($name)
 
 getHeader ($name)
 
 getHeaderLine ($name)
 
 withHeader ($name, $value)
 
 withAddedHeader ($name, $value)
 
 withoutHeader ($name)
 
 getBody ()
 
 withBody (StreamInterface $body)
 
 filter ($value)
 
 validateHeaderName ($name)
 
 isValidHeaderValue ($value)
 

Protected Member Functions

 assertHeaders (array $headers)
 
 filterHeaders (array $originalHeaders)
 
 arrayContainsOnlyStrings (array $data)
 
 validateHeaderValues (array $values)
 

Protected Attributes

 $protocolVersion = '1.1'
 
 $headers = []
 
 $lowercasedHeaderNames = []
 
 $body
 

Detailed Description

Default implementation for the MessageInterface of the PSR-7 standard It is the base for any request or response for PSR-7.

Highly inspired by https://github.com/phly/http/

Definition at line 28 of file core/Classes/Http/Message.php.

Member Function Documentation

arrayContainsOnlyStrings ( array  $data)
protected

Helper function to test if an array contains only strings

Parameters
array$data
Returns
bool

Definition at line 361 of file core/Classes/Http/Message.php.

Referenced by Message\withAddedHeader(), and Message\withHeader().

assertHeaders ( array  $headers)
protected

Ensure header names and values are valid.

Parameters
array$headers
Exceptions
InvalidArgumentException

Definition at line 318 of file core/Classes/Http/Message.php.

References Message\isValidHeaderValue(), and Message\validateHeaderName().

Referenced by Request\__construct(), and Response\__construct().

filter (   $value)

Filter a header value

Ensures CRLF header injection vectors are filtered.

Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal tabs are allowed in values; header continuations MUST consist of a single CRLF sequence followed by a space or horizontal tab.

This method filters any values not allowed from the string, and is lossy.

See also
http://en.wikipedia.org/wiki/HTTP_response_splitting
Parameters
string$value
Returns
string

Definition at line 400 of file core/Classes/Http/Message.php.

filterHeaders ( array  $originalHeaders)
protected

Filter a set of headers to ensure they are in the correct internal format.

Used by message constructors to allow setting all initial headers at once.

Parameters
array$originalHeadersHeaders to filter.
Returns
array Filtered headers and names.

Definition at line 339 of file core/Classes/Http/Message.php.

References Message\$headers.

Referenced by Request\__construct(), and Response\__construct().

getBody ( )

Gets the body of the message.

Returns
Returns the body as a stream.

Definition at line 287 of file core/Classes/Http/Message.php.

References Message\$body.

getHeader (   $name)

Retrieves a message header value by the given case-insensitive name.

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

Parameters
string$nameCase-insensitive header field name.
Returns
string[] An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

Definition at line 145 of file core/Classes/Http/Message.php.

References Message\hasHeader().

Referenced by Message\getHeaderLine().

getHeaderLine (   $name)

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method MUST return an empty string.

Parameters
string$nameCase-insensitive header field name.
Returns
string A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.

Definition at line 178 of file core/Classes/Http/Message.php.

References Message\getHeader().

getHeaders ( )

Retrieves all message header values.

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Returns
array Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

Definition at line 113 of file core/Classes/Http/Message.php.

References Message\$headers.

getProtocolVersion ( )

Retrieves the HTTP protocol version as a string.

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Returns
string HTTP protocol version.

Definition at line 63 of file core/Classes/Http/Message.php.

References Message\$protocolVersion.

hasHeader (   $name)

Checks if a header exists by the given case-insensitive name.

Parameters
string$nameCase-insensitive header field name.
Returns
bool Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.

Definition at line 126 of file core/Classes/Http/Message.php.

Referenced by Message\getHeader(), Request\getHeader(), Request\getHeaders(), Message\withAddedHeader(), and Message\withoutHeader().

isValidHeaderValue (   $value)

Checks if an HTTP header value is valid.

Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal tabs are allowed in values; header continuations MUST consist of a single CRLF sequence followed by a space or horizontal tab.

See also
http://en.wikipedia.org/wiki/HTTP_response_splitting
Parameters
string$value
Returns
bool

Definition at line 459 of file core/Classes/Http/Message.php.

Referenced by Message\assertHeaders(), and Message\validateHeaderValues().

validateHeaderName (   $name)

Check whether or not a header name is valid and throw an exception.

See also
http://tools.ietf.org/html/rfc7230#section-3.2
Parameters
string$name
Exceptions
InvalidArgumentException

Definition at line 441 of file core/Classes/Http/Message.php.

Referenced by Message\assertHeaders(), Message\withAddedHeader(), and Message\withHeader().

validateHeaderValues ( array  $values)
protected

Assert that the provided header values are valid.

See also
http://tools.ietf.org/html/rfc7230#section-3.2
Parameters
string[]$values
Exceptions
InvalidArgumentException

Definition at line 375 of file core/Classes/Http/Message.php.

References Message\isValidHeaderValue().

Referenced by Message\withAddedHeader(), and Message\withHeader().

withAddedHeader (   $name,
  $value 
)

Return an instance with the specified header appended with the given value.

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new header and/or value.

Parameters
string$nameCase-insensitive header field name to add.
string|string[]$value Header value(s).
Returns
Message
Exceptions
InvalidArgumentException for invalid header names or values.

Definition at line 238 of file core/Classes/Http/Message.php.

References Message\arrayContainsOnlyStrings(), Message\hasHeader(), Message\validateHeaderName(), Message\validateHeaderValues(), and Message\withHeader().

withBody ( StreamInterface  $body)

Return an instance with the specified message body.

The body MUST be a StreamInterface object.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.

Parameters
\Psr\Http\Message\StreamInterface$bodyBody.
Returns
Message
Exceptions
InvalidArgumentException When the body is not valid.

Definition at line 305 of file core/Classes/Http/Message.php.

References Message\$body.

withHeader (   $name,
  $value 
)

Return an instance with the provided value replacing the specified header.

While header names are case-insensitive, the casing of the header will be preserved by this function, and returned from getHeaders().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new and/or updated header and value.

Parameters
string$nameCase-insensitive header field name.
string|string[]$value Header value(s).
Returns
Message
Exceptions
InvalidArgumentException for invalid header names or values.

Definition at line 202 of file core/Classes/Http/Message.php.

References Message\arrayContainsOnlyStrings(), Message\validateHeaderName(), and Message\validateHeaderValues().

Referenced by Message\withAddedHeader().

withoutHeader (   $name)

Return an instance without the specified header.

Header resolution MUST be done without case-sensitivity.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the named header.

Parameters
string$nameCase-insensitive header field name to remove.
Returns
Message

Definition at line 269 of file core/Classes/Http/Message.php.

References Message\hasHeader().

withProtocolVersion (   $version)

Return an instance with the specified HTTP protocol version.

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new protocol version.

Parameters
string$versionHTTP protocol version
Returns
Message

Definition at line 81 of file core/Classes/Http/Message.php.

Member Data Documentation

$lowercasedHeaderNames = []
protected

Definition at line 48 of file core/Classes/Http/Message.php.

$protocolVersion = '1.1'
protected

Definition at line 34 of file core/Classes/Http/Message.php.

Referenced by Message\getProtocolVersion().