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.
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.
createServerRequest(string $method, mixed $uri, array $serverParams)
Create a new server request.
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.
string
$method The HTTP method associated with the request.
\Psr\Http\Message\UriInterface|string
$uri The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.
array
$serverParams optional Array of SAPI parameters with which to seed the generated request instance.
\Psr\Http\Message\ServerRequestInterface
createUri(array $server)
Create a new Uri instance from the provided server data.
array
$server optional Array of server data to build the Uri from. $_SERVER will be added into the $server parameter.
\Psr\Http\Message\UriInterface
New instance.
fromGlobals(?array $server, ?array $query, ?array $parsedBody, ?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.
array
$server optional $_SERVER superglobal
array
$query optional $_GET superglobal
array
$parsedBody optional $_POST superglobal
array
$cookies optional $_COOKIE superglobal
array
$files optional $_FILES superglobal
\Cake\Http\ServerRequest
InvalidArgumentException
getBase(\Psr\Http\Message\UriInterface $uri, array $server)
Calculate the base directory and webroot directory.
\Psr\Http\Message\UriInterface
$uri The Uri instance.
array
$server The SERVER data to use.
array
An array containing the [baseDir, webroot]
marshalBodyAndRequestMethod(array $parsedBody, \Cake\Http\ServerRequest $request)
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.
Request body of content type "application/x-www-form-urlencoded" is parsed into array for PUT/PATCH/DELETE requests.
array
$parsedBody Parsed body.
\Cake\Http\ServerRequest
$request Request instance.
\Cake\Http\ServerRequest
marshalFiles(array $files, \Cake\Http\ServerRequest $request)
Process uploaded files and move things onto the parsed body.
array
$files Files array for normalization and merging in parsed body.
\Cake\Http\ServerRequest
$request Request instance.
\Cake\Http\ServerRequest
marshalUriFromSapi(array $server, array $headers)
Build a UriInterface object.
Add in some CakePHP specific logic/properties that help preserve backwards compatibility.
array
$server The server parameters.
array
$headers The normalized headers
\Psr\Http\Message\UriInterface
a constructed Uri
updatePath(string $base, \Psr\Http\Message\UriInterface $uri)
Updates the request URI to remove the base directory.
string
$base The base path to remove.
\Psr\Http\Message\UriInterface
$uri The uri to update.
\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/4.1/class-Cake.Http.ServerRequestFactory.html