ServerRequest
in package
implements
ServerRequestInterface
uses
MessageTrait, RequestTrait
Tags
Table of Contents
Interfaces
- ServerRequestInterface
- Representation of an incoming, server-side HTTP request.
Properties
- $attributes : array<string|int, mixed>
- $cookieParams : array<string|int, mixed>
- $parsedBody : array<string|int, mixed>|object|null
- $queryParams : array<string|int, mixed>
- $serverParams : array<string|int, mixed>
- $uploadedFiles : array<string|int, UploadedFileInterface>
Methods
- __construct() : mixed
- getAttribute() : mixed
- Retrieve a single derived request attribute.
- getAttributes() : array<string|int, mixed>
- Retrieve attributes derived from the request.
- getCookieParams() : array<string|int, mixed>
- Retrieve cookies.
- getParsedBody() : array<string|int, mixed>|object|null
- Retrieve any parameters provided in the request body.
- getQueryParams() : array<string|int, mixed>
- Retrieve query string arguments.
- getServerParams() : array<string|int, mixed>
- Retrieve server parameters.
- getUploadedFiles() : array<string|int, mixed>
- Retrieve normalized file upload data.
- withAttribute() : static
- Return an instance with the specified derived request attribute.
- withCookieParams() : static
- Return an instance with the specified cookies.
- withoutAttribute() : static
- Return an instance that removes the specified derived request attribute.
- withParsedBody() : static
- Return an instance with the specified body parameters.
- withQueryParams() : static
- Return an instance with the specified query string arguments.
- withUploadedFiles() : static
- Create a new instance with the specified uploaded files.
Properties
$attributes
private
array<string|int, mixed>
$attributes
= []
$cookieParams
private
array<string|int, mixed>
$cookieParams
= []
$parsedBody
private
array<string|int, mixed>|object|null
$parsedBody
$queryParams
private
array<string|int, mixed>
$queryParams
= []
$serverParams
private
array<string|int, mixed>
$serverParams
$uploadedFiles
private
array<string|int, UploadedFileInterface>
$uploadedFiles
= []
Methods
__construct()
public
__construct(string $method, string|UriInterface $uri[, array<string|int, mixed> $headers = [] ][, string|resource|StreamInterface|null $body = null ][, string $version = '1.1' ][, array<string|int, mixed> $serverParams = [] ]) : mixed
Parameters
- $method : string
-
HTTP method
- $uri : string|UriInterface
-
URI
- $headers : array<string|int, mixed> = []
-
Request headers
- $body : string|resource|StreamInterface|null = null
-
Request body
- $version : string = '1.1'
-
Protocol version
- $serverParams : array<string|int, mixed> = []
-
Typically the $_SERVER superglobal
getAttribute()
Retrieve a single derived request attribute.
public
getAttribute(mixed $attribute[, mixed $default = null ]) : mixed
Parameters
- $attribute : mixed
- $default : mixed = null
-
Default value to return if the attribute does not exist.
getAttributes()
Retrieve attributes derived from the request.
public
getAttributes() : array<string|int, mixed>
The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.
Return values
array<string|int, mixed> —Attributes derived from the request.
getCookieParams()
Retrieve cookies.
public
getCookieParams() : array<string|int, mixed>
Retrieves cookies sent by the client to the server.
The data MUST be compatible with the structure of the $_COOKIE superglobal.
Return values
array<string|int, mixed>getParsedBody()
Retrieve any parameters provided in the request body.
public
getParsedBody() : array<string|int, mixed>|object|null
Return values
array<string|int, mixed>|object|nullgetQueryParams()
Retrieve query string arguments.
public
getQueryParams() : array<string|int, mixed>
Retrieves the deserialized query string arguments, if any.
Note: the query params might not be in sync with the URI or server
params. If you need to ensure you are only getting the original
values, you may need to parse the query string from getUri()->getQuery()
or from the QUERY_STRING server param.
Return values
array<string|int, mixed>getServerParams()
Retrieve server parameters.
public
getServerParams() : array<string|int, mixed>
Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.
Return values
array<string|int, mixed>getUploadedFiles()
Retrieve normalized file upload data.
public
getUploadedFiles() : array<string|int, mixed>
This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.
These values MAY be prepared from $_FILES or the message body during instantiation, or MAY be injected via withUploadedFiles().
Return values
array<string|int, mixed> —An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.
withAttribute()
Return an instance with the specified derived request attribute.
public
withAttribute(mixed $attribute, mixed $value) : static
Parameters
- $attribute : mixed
- $value : mixed
-
The value of the attribute.
Return values
staticwithCookieParams()
Return an instance with the specified cookies.
public
withCookieParams(array<string|int, mixed> $cookies) : static
Parameters
- $cookies : array<string|int, mixed>
-
Array of key/value pairs representing cookies.
Return values
staticwithoutAttribute()
Return an instance that removes the specified derived request attribute.
public
withoutAttribute(mixed $attribute) : static
Parameters
- $attribute : mixed
Return values
staticwithParsedBody()
Return an instance with the specified body parameters.
public
withParsedBody(mixed $data) : static
Parameters
- $data : mixed
-
The deserialized body data. This will typically be in an array or object.
Return values
staticwithQueryParams()
Return an instance with the specified query string arguments.
public
withQueryParams(array<string|int, mixed> $query) : static
Parameters
- $query : array<string|int, mixed>
-
Array of query string arguments, typically from $_GET.
Return values
staticwithUploadedFiles()
Create a new instance with the specified uploaded files.
public
withUploadedFiles(array<string|int, mixed> $uploadedFiles) : static
Parameters
- $uploadedFiles : array<string|int, mixed>
-
An array tree of UploadedFileInterface instances.