Skip to content
PHP Ecosystem
Explore

ServerRequestAdapter

API reference › PSR bridge › adapter › ServerRequestAdapter

final classyii2\extensions\psrbridge\adapter\ServerRequestAdapter
Sourcesrc/adapter/ServerRequestAdapter.php

Adapts PSR-7 server requests to Yii request expectations.

ServerRequestInterface PSR-7 server request contract.

PropertyTypeDescriptionDefined by
$psrRequest readonlyPsr\Http\Message\ServerRequestInterfaceAdapted PSR-7 ServerRequestInterface instance.ServerRequestAdapter
MethodDescriptionDefined 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
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

ParameterTypeDescription
$psrRequestPsr\Http\Message\ServerRequestInterfaceRequest to adapt.
$parsersarray<string, class-string<object>|array{class?: class-string<object>, __class?: class-string<object>}|callable(): object>Content-Type parser definitions.

Throws

public function getBodyParams(string $methodParam): mixed[]|object

Returns the parsed body, removing the method override key from array bodies when it is non-null.

Parameters

ParameterTypeDescription
$methodParamstringMethod override key to exclude.

Returns

mixed[]|object: Body parameters, or [] when no parsed body exists.

public function getCookies(bool $enableValidation, string $validationKey = ''): yii\web\Cookie[]

Returns PSR cookies with optional Yii signature and encoded-name validation.

Parameters

ParameterTypeDescription
$enableValidationboolWhether to require signed Yii cookie values.
$validationKeystringSecret key, required when validation is enabled.

Returns

yii\web\Cookie[]: Accepted cookies, keyed by cookie name.

Throws

public function getHeaders(): yii\web\HeaderCollection

Retrieves 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.

public function getMethod(string $methodParam = '_method'): string

Retrieves 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

ParameterTypeDescription
$methodParamstringName of the HTTP method override parameter to check in the body (default: _method).

Returns

string: Resolved HTTP method for the request.

public function getParsedBody(): mixed[]|object|null

Retrieves the parsed body parameters from the PSR-7 ServerRequestInterface.

Returns

mixed[]|object|null: Parsed body parameters, or null if not present.

public function getQueryParams(): mixed[]

Returns query parameters from the attached PSR request.

Returns

mixed[]: Query parameters.

public function getQueryString(): string

Retrieves 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.

public function getRawBody(): string

Retrieves 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.

public function getServerParams(): mixed[]

Retrieves server parameters from the PSR-7 ServerRequestInterface.

Returns

mixed[]: Server parameters.

public function getUploadedFiles(): mixed[]

Retrieves uploaded files from the PSR-7 ServerRequestInterface.

Returns

mixed[]: Uploaded files.

public function getUrl(): string

Retrieves 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.