Class ServerRequest
- GuzzleHttp\Psr7\Request implements Psr\Http\Message\RequestInterface uses GuzzleHttp\Psr7\MessageTrait
-
GuzzleHttp\Psr7\ServerRequest implements Psr\Http\Message\ServerRequestInterface
- Namespace: GuzzleHttp\Psr7
- Located at ServerRequest.php
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
- __construct ( string $method, string|UriInterface $uri, array $headers = [], string|resource|StreamInterface|null $body = null, string $version = '1.1', array $serverParams = [] )
-
static
normalizeFiles ( array $files )
Return an UploadedFile instance array.
-
static
fromGlobals ( )
Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER
-
static
getUriFromGlobals ( )
Get a Uri populated with values from $_SERVER.
-
getServerParams ( )
Retrieve server parameters.
-
getUploadedFiles ( )
Retrieve normalized file upload data.
-
withUploadedFiles ( array $uploadedFiles )
Create a new instance with the specified uploaded files.
-
getCookieParams ( )
Retrieve cookies.
-
withCookieParams ( array $cookies )
Return an instance with the specified cookies.
-
getQueryParams ( )
Retrieve query string arguments.
-
withQueryParams ( array $query )
Return an instance with the specified query string arguments.
-
getParsedBody ( )
Retrieve any parameters provided in the request body.
-
withParsedBody ( null|array|object $data )
Return an instance with the specified body parameters.
-
getAttributes ( )
Retrieve attributes derived from the request.
-
getAttribute ( string $attribute, mixed $default = null )
Retrieve a single derived request attribute.
-
withAttribute ( string $attribute, mixed $value )
Return an instance with the specified derived request attribute.
-
withoutAttribute ( string $attribute )
Return an instance that removes the specified derived request attribute.
Methods inherited from GuzzleHttp\Psr7\Request
Methods inherited from Psr\Http\Message\MessageInterface
getBody()
,
getHeader()
,
getHeaderLine()
,
getHeaders()
,
getProtocolVersion()
,
hasHeader()
,
withAddedHeader()
,
withBody()
,
withHeader()
,
withProtocolVersion()
,
withoutHeader()
Methods used from GuzzleHttp\Psr7\MessageTrait
Methods Details
__construct (
string
$method,
string|Psr\Http\Message\UriInterface
$uri,
array
$headers = [],
string|resource|Psr\Http\Message\StreamInterface
|null
$body = null,
string
$version = '1.1',
array
$serverParams = []
)
Parameters
string | $method | HTTP method |
string|Psr\Http\Message\UriInterface |
$uri | URI |
array | $headers = [] | Request headers |
string|resource|Psr\Http\Message\StreamInterface |null |
$body = null | Request body |
string | $version = '1.1' | Protocol version |
array | $serverParams = [] | Typically the $_SERVER superglobal |
Overrides
static array normalizeFiles ( array $files )
Return an UploadedFile instance array.
Parameters
array | $files | A array which respect $_FILES structure |
Returns
array |
Exceptions
InvalidArgumentException for unrecognized values |
static
Psr\Http\Message\ServerRequestInterface
fromGlobals (
)
Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER
Returns
Psr\Http\Message\ServerRequestInterface |
static
Psr\Http\Message\UriInterface
getUriFromGlobals (
)
array getServerParams ( )
Retrieve server parameters.
Returns
array |
Implementation of
array getUploadedFiles ( )
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
static withUploadedFiles ( array $uploadedFiles )
Create a new instance with the specified uploaded files.
Parameters
array | $uploadedFiles | An array tree of UploadedFileInterface instances. |
Returns
static |
Exceptions
InvalidArgumentException if an invalid structure is provided. |
Implementation of
array getCookieParams ( )
Retrieve cookies.
Returns
array |
Implementation of
static withCookieParams ( array $cookies )
Return an instance with the specified cookies.
Parameters
array | $cookies | Array of key/value pairs representing cookies. |
Returns
static |
Implementation of
array getQueryParams ( )
Retrieve query string arguments.
Returns
array |
Implementation of
static withQueryParams ( array $query )
Return an instance with the specified query string arguments.
Parameters
array | $query | Array of query string arguments, typically from $_GET. |
Returns
static |
Implementation of
null|array|object getParsedBody ( )
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
static withParsedBody ( null|array|object $data )
Return an instance with the specified body parameters.
Parameters
null|array|object | $data | The deserialized body data. This will typically be in an array or object. |
Returns
static |
Exceptions
InvalidArgumentException if an unsupported argument type is provided. |
Implementation of
array getAttributes ( )
Retrieve attributes derived from the request.
Returns
array Attributes derived from the request. |
Implementation of
mixed getAttribute ( string $attribute, mixed $default = null )
Retrieve a single derived request attribute.
Parameters
string | $attribute | $name The attribute name. |
mixed | $default = null | Default value to return if the attribute does not exist. |
Returns
mixed |
Implementation of
static withAttribute ( string $attribute, mixed $value )
Return an instance with the specified derived request attribute.
Parameters
string | $attribute | $name The attribute name. |
mixed | $value | The value of the attribute. |
Returns
static |
Implementation of
static withoutAttribute ( string $attribute )
Return an instance that removes the specified derived request attribute.
Parameters
string | $attribute | $name The attribute name. |
Returns
static |