Method
ServerRequest::__construct
Creates a server request.
Description#
public ServerRequest::__construct(
string $method,
string $requestTarget,
StreamInterface|Closure|null $body,
array $headers = [],
?array $queryParams = null,
array $serverParams = [],
array $cookieParams = [],
Closure|array $uploadedFiles = [],
mixed $parsedBody = null,
array $attributes = [],
string $protocolVersion = '1.1'
)A Closure given for the body, the uploaded files or the parsed body is called each time that is asked for, until a with...() method replaces it: a server can parse the body on demand, and every clone sees the same state.
Parameters#
- $method string
- Case-sensitive HTTP method
- $requestTarget string
- Request target, e.g. "/path?query=value"
- $body StreamInterface|Closure|null
- Body; null is an empty stream; a Closure returning the stream
- $headers array = []
- Array of header names => values
- $queryParams ?array = null
- Query params override; null derives them from the request target
- $serverParams array = []
- Server params, like $_SERVER
- $cookieParams array = []
- Cookie params, like $_COOKIE
- $uploadedFiles Closure|array = []
- Tree of uploaded file instances, or a Closure returning it
- $parsedBody mixed = null
- Deserialized body data, or a Closure returning it
- $attributes array = []
- Attributes derived from the request
- $protocolVersion string = '1.1'
- The HTTP protocol version, typically "1.1" or "1.0"
Errors / Exceptions#
| Exception | When |
|---|---|
InvalidArgumentException | For a method that is not an RFC 7230 token, a request target containing whitespace or control characters, an invalid header (a value that is not a string is rejected), or $uploadedFiles that is not a tree of UploadedFileInterface |