ServerRequestAdapter
API reference › PSR bridge › adapter › ServerRequestAdapter
Adapts PSR-7 server requests to Yii request expectations.
ServerRequestInterface PSR-7 server request contract.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$psrRequest readonly | Psr\ | Adapted PSR-7 ServerRequestInterface instance. | ServerRequestAdapter |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Adapts a PSR-7 request and parses its body when a matching parser is configured. | ServerRequestAdapter |
getBodyParams() | Returns the parsed body, removing the method override key from array bodies when it is non-null. | ServerRequestAdapter |
getCookies() | Returns PSR cookies with optional Yii signature and encoded-name validation. | ServerRequestAdapter |
getHeaders() | Retrieves all HTTP headers from the PSR-7 ServerRequestInterface as a Yii HeaderCollection instance. | ServerRequestAdapter |
getMethod() | Retrieves the HTTP method for the current request, supporting method override via body or header. | ServerRequestAdapter |
getParsedBody() | Retrieves the parsed body parameters from the PSR-7 ServerRequestInterface. | ServerRequestAdapter |
getQueryParams() | Returns query parameters from the attached PSR request. | ServerRequestAdapter |
getQueryString() | Retrieves the raw query string from the PSR-7 ServerRequestInterface URI. | ServerRequestAdapter |
getRawBody() | Retrieves the raw body content from the PSR-7 ServerRequestInterface stream. | ServerRequestAdapter |
getServerParams() | Retrieves server parameters from the PSR-7 ServerRequestInterface. | ServerRequestAdapter |
getUploadedFiles() | Retrieves uploaded files from the PSR-7 ServerRequestInterface. | ServerRequestAdapter |
getUrl() | Retrieves the request URL path and query string from the PSR-7 URI. | ServerRequestAdapter |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Psr\Http\Message\ServerRequestInterface $psrRequest, array<string, class-string<object>|array{class?: class-string<object>, __class?: class-string<object>}|callable(): object> $parsers = [])Adapts a PSR-7 request and parses its body when a matching parser is configured.
Requests that already contain a parsed body are left unchanged.
Parameters
| Parameter | Type | Description |
|---|---|---|
$psrRequest | Psr\ | Request to adapt. |
$parsers | array<string, | Content-Type parser definitions. |
Throws
yii\base\InvalidConfigException: if a configured parser does not implement RequestParserInterface.
getBodyParams()
Section titled “getBodyParams() ”public function getBodyParams(string $methodParam): mixed[]|objectReturns the parsed body, removing the method override key from array bodies when it is non-null.
Parameters
| Parameter | Type | Description |
|---|---|---|
$methodParam | string | Method override key to exclude. |
Returns
mixed[]|object: Body parameters, or [] when no parsed body exists.
getCookies()
Section titled “getCookies() ”public function getCookies(bool $enableValidation, string $validationKey = ''): yii\web\Cookie[]Returns PSR cookies with optional Yii signature and encoded-name validation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$enableValidation | bool | Whether to require signed Yii cookie values. |
$validationKey | string | Secret key, required when validation is enabled. |
Returns
yii\web\Cookie[]: Accepted cookies, keyed by cookie name.
Throws
yii\base\InvalidConfigException: when validation is enabled without a key.
getHeaders()
Section titled “getHeaders() ”public function getHeaders(): yii\web\HeaderCollectionRetrieves all HTTP headers from the PSR-7 ServerRequestInterface as a Yii HeaderCollection instance.
Iterates over each header in the PSR-7 ServerRequestInterface and adds it to a new HeaderCollection
instance, concatenating multiple values with a comma and space, as expected by Yii.
Returns
yii\web\HeaderCollection: Collection of HTTP headers from the PSR-7 ServerRequestInterface.
getMethod()
Section titled “getMethod() ”public function getMethod(string $methodParam = '_method'): stringRetrieves the HTTP method for the current request, supporting method override via body or header.
Determines the HTTP method by checking for an override parameter in the parsed body (such as _method) or the
X-Http-Method-Override header.
- If a valid override is found and is not one of GET, HEAD, or OPTIONS, it is returned in uppercase.
- Otherwise, the original method from the PSR-7 ServerRequestInterface is returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$methodParam | string | Name of the HTTP method override parameter to check in the body (default: _method). |
Returns
string: Resolved HTTP method for the request.
getParsedBody()
Section titled “getParsedBody() ”public function getParsedBody(): mixed[]|object|nullRetrieves the parsed body parameters from the PSR-7 ServerRequestInterface.
Returns
mixed[]|object|null: Parsed body parameters, or null if not present.
getQueryParams()
Section titled “getQueryParams() ”public function getQueryParams(): mixed[]Returns query parameters from the attached PSR request.
Returns
mixed[]: Query parameters.
getQueryString()
Section titled “getQueryString() ”public function getQueryString(): stringRetrieves the raw query string from the PSR-7 ServerRequestInterface URI.
Returns
string: Raw query string from the request URI, or an empty string if not present.
getRawBody()
Section titled “getRawBody() ”public function getRawBody(): stringRetrieves the raw body content from the PSR-7 ServerRequestInterface stream.
The stream is rewound before reading (if seekable) to ensure the full content is returned from the beginning.
Returns
string: Raw body content from the PSR-7 ServerRequestInterface stream.
getServerParams()
Section titled “getServerParams() ”public function getServerParams(): mixed[]Retrieves server parameters from the PSR-7 ServerRequestInterface.
Returns
mixed[]: Server parameters.
getUploadedFiles()
Section titled “getUploadedFiles() ”public function getUploadedFiles(): mixed[]Retrieves uploaded files from the PSR-7 ServerRequestInterface.
Returns
mixed[]: Uploaded files.
getUrl()
Section titled “getUrl() ”public function getUrl(): stringRetrieves the request URL path and query string from the PSR-7 URI.
This method provides the full URL as seen by the application, excluding the scheme, host, and fragment, ensuring compatibility with Yii Routing and Request processing expectations.
- If the URI contains a query string, it is appended to the path with a ’?’ separator.
- If no query string is present, only the path is returned.
Returns
string: Request URL path and query string, excluding scheme, host, and fragment.