Class ServerRequestFactory

Factory for making ServerRequest instances.

This subclass adds in CakePHP specific behavior to populate the basePath and webroot attributes. Furthermore the Uri's path is corrected to only contain the 'virtual' path for the request.

Abstract
Namespace: Cake\Http

Method Summary

Method Detail

createUri() public static

createUri(array $server)

Create a new Uri instance from the provided server data.

Parameters

array $server optional

Array of server data to build the Uri from. $_SERVER will be added into the $server parameter.

Returns

\Psr\Http\Message\UriInterface

New instance.

fromGlobals() public static

fromGlobals(array $server, array $query, array $body, array $cookies, array $files)

Create a request from the supplied superglobal values.

If any argument is not supplied, the corresponding superglobal value will be used.

The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers.

Parameters

array $server optional

$_SERVER superglobal

array $query optional

$_GET superglobal

array $body optional

$_POST superglobal

array $cookies optional

$_COOKIE superglobal

array $files optional

$_FILES superglobal

Returns

\Laminas\Diactoros\ServerRequest

Throws

InvalidArgumentException
for invalid file values

See Also

\Laminas\Diactoros\fromServer()

get() public static

get(mixed $key, array $values, mixed $default)

Access a value in an array, returning a default value if not found

Parameters

string $key
array $values
mixed $default optional

Returns

mixed

getBase() protected static

getBase(mixed $uri, mixed $server)

Calculate the base directory and webroot directory.

Parameters

\Psr\Http\Message\UriInterface $uri

The Uri instance.

array $server

The SERVER data to use.

Returns

array

An array containing the [baseDir, webroot]

getHeader() public static

getHeader(mixed $header, array $headers, mixed $default)

Search for a header value.

Does a case-insensitive search for a matching header.

If found, it is returned as a string, using comma concatenation.

If not, the $default is returned.

Parameters

string $header
array $headers
mixed $default optional

Returns

string

marshalHeaders() public static

marshalHeaders(array $server)

Marshal headers from $_SERVER

Parameters

array $server

Returns

array

marshalHostAndPortFromHeaders() public static

marshalHostAndPortFromHeaders(\stdClass $accumulator, array $server, array $headers)

Marshal the host and port from HTTP headers and/or the PHP environment

Parameters

\stdClass $accumulator
array $server
array $headers

marshalRequestUri() public static

marshalRequestUri(array $server)

Detect the base URI for the request

Looks at a variety of criteria in order to attempt to autodetect a base URI, including rewrite URIs, proxy URIs, etc.

Parameters

array $server

Returns

string

marshalUriFromServer() public static

marshalUriFromServer(array $server, array $headers)

Build a UriInterface object.

Add in some CakePHP specific logic/properties that help preserve backwards compatibility.

Parameters

array $server

The server parameters.

array $headers

The normalized headers

Returns

\Psr\Http\Message\UriInterface

a constructed Uri

normalizeFiles() public static

normalizeFiles(array $files)

Normalize uploaded files

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

Parameters

array $files

Returns

array

Throws

InvalidArgumentException
for unrecognized values

normalizeServer() public static

normalizeServer(array $server)

Marshal the $_SERVER array

Pre-processes and returns the $_SERVER superglobal.

Parameters

array $server

Returns

array

stripQueryString() public static

stripQueryString(mixed $path)

Strip the query string from a path

Parameters

mixed $path

Returns

string

updatePath() protected static

updatePath(mixed $base, mixed $uri)

Updates the request URI to remove the base directory.

Parameters

string $base

The base path to remove.

\Psr\Http\Message\UriInterface $uri

The uri to update.

Returns

\Psr\Http\Message\UriInterface

The modified Uri instance.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Http.ServerRequestFactory.html