Class ServerRequestFactory
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.
Method Summary
- 
          createServerRequest() publicCreate a new server request. 
- 
          fromGlobals() public staticCreate a request from the supplied superglobal values. 
- 
          marshalBodyAndRequestMethod() protected staticSets 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() protected staticProcess uploaded files and move things onto the parsed body. 
Method Detail
createServerRequest() ¶ public
createServerRequest(string $method, UriInterface|string $uri, array $serverParams = []): Psr\Http\Message\ServerRequestInterfaceCreate 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.
Parameters
- 
                string$method
- The HTTP method associated with the request. 
- 
                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. 
Returns
Psr\Http\Message\ServerRequestInterfacefromGlobals() ¶ public static
fromGlobals(array|null $server = null, array|null $query = null, array|null $parsedBody = null, array|null $cookies = null, array|null $files = null): Cake\Http\ServerRequestCreate a request from the supplied superglobal values.
If any argument is not supplied, the corresponding superglobal value will be used.
Parameters
- 
                array|null$server optional
- $_SERVER superglobal 
- 
                array|null$query optional
- $_GET superglobal 
- 
                array|null$parsedBody optional
- $_POST superglobal 
- 
                array|null$cookies optional
- $_COOKIE superglobal 
- 
                array|null$files optional
- $_FILES superglobal 
Returns
Cake\Http\ServerRequestThrows
InvalidArgumentExceptionfor invalid file values
marshalBodyAndRequestMethod() ¶ protected static
marshalBodyAndRequestMethod(array $parsedBody, Cake\Http\ServerRequest $request): Cake\Http\ServerRequestSets 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.
Parameters
- 
                array$parsedBody
- Parsed body. 
- 
                Cake\Http\ServerRequest$request
- Request instance. 
Returns
Cake\Http\ServerRequestmarshalFiles() ¶ protected static
marshalFiles(array $files, Cake\Http\ServerRequest $request): Cake\Http\ServerRequestProcess uploaded files and move things onto the parsed body.
Parameters
- 
                array$files
- Files array for normalization and merging in parsed body. 
- 
                Cake\Http\ServerRequest$request
- Request instance. 
Returns
Cake\Http\ServerRequest