\ZendDiactoros

Namespaces

Exception
Request
Response

Traits

MessageTrait Trait implementing the various methods defined in MessageInterface.
RequestTrait Trait with common request behaviors.

Classes

AbstractSerializer 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.
CallbackStream Implementation of PSR HTTP streams
HeaderSecurity Provide security tools around HTTP headers to prevent common injection vectors.
PhpInputStream Caching version of php://input
RelativeStream Class RelativeStream
Request HTTP Request encapsulation
Response HTTP response encapsulation.
Server "Serve" incoming HTTP requests
ServerRequest Server-side HTTP request
ServerRequestFactory Class for marshaling a request object from the current PHP environment.
Stream Implementation of PSR HTTP streams
UploadedFile
Uri Implementation of Psr\Http\UriInterface.

Functions

createUploadedFile()

createUploadedFile(array  $spec) : \Zend\Diactoros\UploadedFile

Create an uploaded file instance from an array of values.

Parameters

array $spec

A single $_FILES entry.

Throws

\InvalidArgumentException

if one or more of the tmp_name, size, or error keys are missing from $spec.

Returns

\Zend\Diactoros\UploadedFile

marshalHeadersFromSapi()

marshalHeadersFromSapi(array  $server) : array

Parameters

array $server

Values obtained from the SAPI (generally $_SERVER).

Returns

array —

Header/value pairs

marshalMethodFromSapi()

marshalMethodFromSapi(array  $server) : string

Retrieve the request method from the SAPI parameters.

Parameters

array $server

Returns

string

marshalProtocolVersionFromSapi()

marshalProtocolVersionFromSapi(array  $server) : string

Return HTTP protocol version (X.Y) as discovered within a `$_SERVER` array.

Parameters

array $server

Throws

\UnexpectedValueException

if the $server['SERVER_PROTOCOL'] value is malformed.

Returns

string

marshalUriFromSapi()

marshalUriFromSapi(array  $server, array  $headers) : \Zend\Diactoros\Uri

Marshal a Uri instance based on the values presnt in the $_SERVER array and headers.

Parameters

array $server

SAPI parameters

array $headers

HTTP request headers

Returns

\Zend\Diactoros\Uri

normalizeServer()

normalizeServer(array  $server, null|callable  $apacheRequestHeaderCallback = null) : array

Marshal the $_SERVER array

Pre-processes and returns the $_SERVER superglobal. In particularly, it attempts to detect the Authorization header, which is often not aggregated correctly under various SAPI/httpd combinations.

Parameters

array $server
null|callable $apacheRequestHeaderCallback

Callback that can be used to retrieve Apache request headers. This defaults to apache_request_headers under the Apache mod_php.

Returns

array —

Either $server verbatim, or with an added HTTP_AUTHORIZATION header.

normalizeUploadedFiles()

normalizeUploadedFiles(array  $files) : array<mixed,\Psr\Http\Message\UploadedFileInterface>

Normalize uploaded files

Transforms each value into an UploadedFile instance, and ensures that nested arrays are normalized.

Parameters

array $files

Throws

\InvalidArgumentException

for unrecognized values

Returns

array<mixed,\Psr\Http\Message\UploadedFileInterface>

parseCookieHeader()

parseCookieHeader(string  $cookieHeader) : array

Parse a cookie header according to RFC 6265.

PHP will replace special characters in cookie names, which results in other cookies not being available due to overwriting. Thus, the server request should take the cookies from the request header instead.

Parameters

string $cookieHeader

A string cookie header value.

Returns

array —

key/value cookie pairs.