Fr3nch13/CakePHP Utilities

ServerRequestFactory
in package
implements ServerRequestFactoryInterface

AbstractYes

Factory for making ServerRequest instances.

This 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.

Table of Contents

Interfaces

ServerRequestFactoryInterface

Methods

createServerRequest()  : ServerRequestInterface
Create a new server request.
createUri()  : UriInterface
Create a new Uri instance from the provided server data.
fromGlobals()  : ServerRequest
Create a request from the supplied superglobal values.
getBase()  : array<string|int, mixed>
Calculate the base directory and webroot directory.
marshalBodyAndRequestMethod()  : ServerRequest
Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value. The 'ORIGINAL_REQUEST_METHOD' is also preserved, if you want the read the non-simulated HTTP method the client used.
marshalFiles()  : ServerRequest
Process uploaded files and move things onto the parsed body.
marshalUriFromSapi()  : Uri
Build a UriInterface object.
updatePath()  : UriInterface
Updates the request URI to remove the base directory.

Methods

createServerRequest()

Create a new server request.

public createServerRequest(string $method, UriInterface|string $uri[, array<string|int, mixed> $serverParams = [] ]) : ServerRequestInterface

Note that server-params are taken precisely as given - no parsing/processing of the given values is performed, and, in particular, no attempt is made to determine the HTTP method or URI, which must be provided explicitly.

Parameters
$method : string

The HTTP method associated with the request.

$uri : UriInterface|string

The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.

$serverParams : array<string|int, mixed> = []

Array of SAPI parameters with which to seed the generated request instance.

Return values
ServerRequestInterface

createUri()

Create a new Uri instance from the provided server data.

public static createUri([array<string|int, mixed> $server = [] ]) : UriInterface
Parameters
$server : array<string|int, mixed> = []

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

Return values
UriInterface

New instance.

fromGlobals()

Create a request from the supplied superglobal values.

public static fromGlobals([array<string|int, mixed>|null $server = null ][, array<string|int, mixed>|null $query = null ][, array<string|int, mixed>|null $parsedBody = null ][, array<string|int, mixed>|null $cookies = null ][, array<string|int, mixed>|null $files = null ]) : ServerRequest

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

Parameters
$server : array<string|int, mixed>|null = null

$_SERVER superglobal

$query : array<string|int, mixed>|null = null

$_GET superglobal

$parsedBody : array<string|int, mixed>|null = null

$_POST superglobal

$cookies : array<string|int, mixed>|null = null

$_COOKIE superglobal

$files : array<string|int, mixed>|null = null

$_FILES superglobal

Tags
throws
InvalidArgumentException

for invalid file values

Return values
ServerRequest

getBase()

Calculate the base directory and webroot directory.

protected static getBase(UriInterface $uri, array<string|int, mixed> $server) : array<string|int, mixed>
Parameters
$uri : UriInterface

The Uri instance.

$server : array<string|int, mixed>

The SERVER data to use.

Return values
array<string|int, mixed>

An array containing the [baseDir, webroot]

marshalBodyAndRequestMethod()

Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value. The 'ORIGINAL_REQUEST_METHOD' is also preserved, if you want the read the non-simulated HTTP method the client used.

protected static marshalBodyAndRequestMethod(array<string|int, mixed> $parsedBody, ServerRequest $request) : ServerRequest

Request body of content type "application/x-www-form-urlencoded" is parsed into array for PUT/PATCH/DELETE requests.

Parameters
$parsedBody : array<string|int, mixed>

Parsed body.

$request : ServerRequest

Request instance.

Return values
ServerRequest

marshalFiles()

Process uploaded files and move things onto the parsed body.

protected static marshalFiles(array<string|int, mixed> $files, ServerRequest $request) : ServerRequest
Parameters
$files : array<string|int, mixed>

Files array for normalization and merging in parsed body.

$request : ServerRequest

Request instance.

Return values
ServerRequest

marshalUriFromSapi()

Build a UriInterface object.

protected static marshalUriFromSapi(array<string|int, mixed> $server, array<string|int, mixed> $headers) : Uri

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

Parameters
$server : array<string|int, mixed>

The server parameters.

$headers : array<string|int, mixed>

The normalized headers

Return values
Uri

A constructed Uri


        
On this page

Search results