Server-side HTTP request
Extends the Request definition to add methods for accessing incoming data,
specifically server parameters, cookies, matched path parameters, query
string arguments, body parameters, and upload file information.
"Attributes" are discovered via decomposing the request (and usually
specifically the URI path), and typically will be injected by the application.
Requests are considered immutable; all methods that might change state are
implemented such that they retain the internal state of the current
message and return a new instance that contains the changed state.
Methods summary
public
|
#
__construct( string $method, string|Psr\Http\Message\UriInterface $uri, array $headers = [], string|null|resource|Psr\Http\Message\StreamInterface $body = null, string $version = '1.1', array $serverParams = [] )
Parameters
- $method
- HTTP method
- $uri
- URI
- $headers
- Request headers
- $body
- Request body
- $version
- Protocol version
- $serverParams
- Typically the $_SERVER superglobal
Overrides
|
public static
array
|
#
normalizeFiles( array $files )
Return an UploadedFile instance array.
Return an UploadedFile instance array.
Parameters
- $files
- A array which respect $_FILES structure
Returns
array
Throws
InvalidArgumentException for unrecognized values
|
public static
Psr\Http\Message\ServerRequestInterface
|
#
fromGlobals( )
Return a ServerRequest populated with superglobals:
$_GET
$_POST
$_COOKIE
$_FILES
$_SERVER
Return a ServerRequest populated with superglobals:
$_GET
$_POST
$_COOKIE
$_FILES
$_SERVER
Returns
|
public static
Psr\Http\Message\UriInterface
|
#
getUriFromGlobals( )
Get a Uri populated with values from $_SERVER.
Get a Uri populated with values from $_SERVER.
Returns
|
public
array
|
#
getServerParams( )
Retrieve server parameters.
Retrieve server parameters.
Returns
array
Implementation of
|
public
array
|
#
getUploadedFiles( )
Retrieve normalized file upload data.
Retrieve normalized file upload data.
Returns
array An array tree of UploadedFileInterface instances; an empty
array MUST be returned if no data is present.
Implementation of
|
public
static
|
#
withUploadedFiles( array $uploadedFiles )
Create a new instance with the specified uploaded files.
Create a new instance with the specified uploaded files.
Parameters
- $uploadedFiles
- An array tree of UploadedFileInterface instances.
Returns
static
Throws
InvalidArgumentException if an invalid structure is provided.
Implementation of
|
public
array
|
|
public
static
|
#
withCookieParams( array $cookies )
Return an instance with the specified cookies.
Return an instance with the specified cookies.
Parameters
- $cookies
- Array of key/value pairs representing cookies.
Returns
static
Implementation of
|
public
array
|
#
getQueryParams( )
Retrieve query string arguments.
Retrieve query string arguments.
Returns
array
Implementation of
|
public
static
|
#
withQueryParams( array $query )
Return an instance with the specified query string arguments.
Return an instance with the specified query string arguments.
Parameters
- $query
Array of query string arguments, typically from
$_GET.
Returns
static
Implementation of
|
public
null|array|object
|
#
getParsedBody( )
Retrieve any parameters provided in the request body.
Retrieve any parameters provided in the request body.
Returns
null|array|object The deserialized body parameters, if any.
These will typically be an array or object.
Implementation of
|
public
static
|
#
withParsedBody( null|array|object $data )
Return an instance with the specified body parameters.
Return an instance with the specified body parameters.
Parameters
- $data
The deserialized body data. This will
typically be in an array or object.
Returns
static
Throws
InvalidArgumentException if an unsupported argument type is
provided.
Implementation of
|
public
array
|
#
getAttributes( )
Retrieve attributes derived from the request.
Retrieve attributes derived from the request.
Returns
array Attributes derived from the request.
Implementation of
|
public
mixed
|
#
getAttribute( string $attribute, mixed $default = null )
Retrieve a single derived request attribute.
Retrieve a single derived request attribute.
Parameters
- $attribute
- $name The attribute name.
- $default
- Default value to return if the attribute does not exist.
Returns
mixed
Implementation of
|
public
static
|
#
withAttribute( string $attribute, mixed $value )
Return an instance with the specified derived request attribute.
Return an instance with the specified derived request attribute.
Parameters
- $attribute
- $name The attribute name.
- $value
- The value of the attribute.
Returns
static
Implementation of
|
public
static
|
#
withoutAttribute( string $attribute )
Return an instance that removes the specified derived request attribute.
Return an instance that removes the specified derived request attribute.
Parameters
- $attribute
- $name The attribute name.
Returns
static
Implementation of
|