Luminova Framework

PHP Luminova: Incoming HTTP Request Object

Last updated: 2026-11-28 20:57:12

Incoming HTTP request class, offering a secure and consistent interface to retrieve query parameters, form inputs, headers, files, and server information, enabling easy request handling.

The Request class represents an incoming HTTP request, encapsulating all relevant data sent by the client, including headers, query parameters, form inputs, cookies, server variables, and uploaded files. It provides a structured and secure interface for accessing and manipulating request data, ensuring consistency across web applications.

In addition to basic data retrieval, the Request class includes built-in authentication mechanisms, allowing validation of requests based on trusted origins, proxy headers, or allowed domain rules. This makes it easier to implement security measures such as CSRF protection, origin checks, and proxy validation without adding additional layers of complexity.

By abstracting low-level server interactions, the Request class helps request handling, improves application security, and simplifies application development in HTTP-based services.


Accessing Object

The request object can be accessed in multiple ways, depending on the context. You can use the global helper function, the Factory class, or the Controller class.

Access Methods

1. Using Global Helper Function

use function Luminova\Funcs\request;

$request = request();

2. Accessing Through the Factory Class

use Luminova\Foundation\Module\Factory;

$request = Factory::request();

3. Initializing the Request Instance Directly

use Luminova\Http\Request;

$request = new Request();

4. Accessing in Controller Classes

If your controller extends Luminova\Base\Http\AbstractController.

$this->request->fooMethod();

Class Definition


Properties

server

Http server params instance.

public readonly ?Luminova\Http\Server $server;

header

Http request header instance.

public readonly ?Luminova\Http\Header $header;

agent

Browser request user-agent information.

public readonly ?Luminova\Http\UserAgent $agent;

Methods

constructor

Create a new HTTP request representing an incoming client request.

This constructor optionally accept request properties like method, URI, body, files, server parameters, and headers. allowing you to create a custom HTTP request. Files are normalized to PSR-7 UploadedFileInterface instances.

public function __construct(
    ?string $method = null,
    UriInterface|string|null $uri = null,
    StreamInterface|array $body = [],
    array $files = [],
    ?array $cookies = null,
    ?array $serverParams = null,
    ?array $headers = null,
    ?string $protocolVersion = null
)

Parameters:

ParameterTypeDescription
$methodstring|nullThe HTTP method (e.g., GET, Luminova\Http\Method::POST).
$uriUriInterface|string|nullThe request URI object or a string containing path and query.
$bodyStreamInterface|array<string, mixed>Request body. Can be a PSR-7 stream or an associative array (form data, JSON, etc.).
$filesUploadedFileInterface[]\array<string, array>Uploaded files object or an associative array (e.g., ['image' => [...]])..
$cookiesarray<string, mixed>Optional associative array of Cookies (e.g, $_COOKIE).
$serverParamsarray<string, mixed>|nullOptional server parameters (e.g., $_SERVER).
$headersarray<string, mixed>|nullOptional HTTP headers.
If not provided, they will be extracted from apache_request_headers() or $_SERVER.
$protocolVersionstring|nullHTTP protocol version (default: null).

Example

Create a new request-response object by passing appropriate values.

$request = new Luminova\Http\Request(
    method: 'POST',
    uri: '/api/v1/users',
    body: ['name' => 'John Doe', 'email' => '[email protected]'], 
    files: [
        'image' => [
            'name' => 'profile.jpg',
            'type' => 'image/jpeg',
            'tmp_name' => '/tmp/phpYzdqkD',
            'error' => 0,
            'size' => 123456
        ]
    ],
    serverParams: [
        'REQUEST_METHOD' => 'POST',
        'REMOTE_ADDR' => '192.168.1.10',
        'HTTP_USER_AGENT' => 'Mozilla/5.0',
        'SERVER_PROTOCOL' => 'HTTP/1.1',
        'SERVER_NAME' => 'example.com',
        'REQUEST_URI' => '/api/v1/users',
    ],
    headers: [
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer some-token',
        'Accept' => 'application/json',
        'X-Custom-Header' => 'CustomValue'
    ] 
);

echo $request->getPost('name'); //John Doe

// Or using ANY
echo $request->input('name'); //John Doe

Supported Array File Structures

PHP File Upload Structure:

[
    'images' => [
        'name'      => ['file1.jpg', 'file2.png', 'file3.gif'],
        'type'      => ['image/jpeg', 'image/png', 'image/gif'],
        'tmp_name'  => ['/tmp/phpYzdqkD', '/tmp/phpeEwEWq', '/tmp/php7sdfXy'],
        'error'     => [0, 0, 0],
        'size'      => [123456, 234567, 345678]
    ]
];

Flat File Structure:

[
   'images' => [
        [
            'name' => 'file1.jpg',
            'type' => 'image/jpeg',
            'tmp_name' => '/tmp/phpYzdqkD',
            'error' => 0,
            'size' => 123456
        ],
        [
            'name' => 'file2.png',
            'type' => 'image/png',
            'tmp_name' => '/tmp/phpeEwEWq',
            'error' => 0,
            'size' => 234567
        ],
        [
            'name' => 'file3.gif',
            'type' => 'image/gif',
            'tmp_name' => '/tmp/php7sdfXy',
            'error' => 0,
            'size' => 345678
        ]
   ]
];

Note: This structure may be developer-friendly, but it isn't the standard way PHP handles uploaded files.


getInstance

Returns a shared instance of HTTP request representing an incoming client request.

public static function getInstance(
    ?string $method = null,
    UriInterface|string|null $uri = null,
    StreamInterface|array $body = [],
    array $files = [],
    ?array $cookies = null,
    ?array $serverParams = null,
    ?array $headers = null,
    ?string $protocolVersion = null
): self

Parameters:

ParameterTypeDescription
$methodstring|nullThe HTTP method (e.g., GET, Luminova\Http\Method::POST).
$uriUriInterface|string|nullThe request URI object or a string containing path and query.
$bodyStreamInterface|array<string, mixed>Request body. Can be a PSR-7 stream or an associative array (form data, JSON, etc.).
$filesUploadedFileInterface[]\array<string, array>Uploaded files object or an associative array (e.g., ['image' => [...]])..
$cookiesarray<string, mixed>Optional associative array of Cookies (e.g, $_COOKIE).
$serverParamsarray<string, mixed>|nullOptional server parameters (e.g., $_SERVER).
$headersarray<string, mixed>|nullOptional HTTP headers.
If not provided, they will be extracted from apache_request_headers() or $_SERVER.
$protocolVersionstring|nullHTTP protocol version (default: null).

Return:

RequestInterface - Return new or shared instance of request object.


toString

Converts the request body to a raw string format based on the content type.

public function toString(): string

Return:

string - Return the raw string representation of the request body.

Supported Content Types:

  • application/x-www-form-urlencoded: Converts the body to a URL-encoded query string.
  • application/json: Converts the body to a JSON string.
  • multipart/form-data: Converts the body to a multipart/form-data format.

toMultipart

Converts the request body to a multipart/form-data string format.

public function toMultipart(): string

Return:

string - Return the multipart form-data representation of the request body.


setField

Set a specific field in the request body for the given HTTP method.

public function setField(string $field, mixed $value, ?string $method = null): self

Parameters:

ParameterTypeDescription
$fieldstringThe name of the field to set.
$valuemixedThe value to assign to the field.
$methodstring|nullOptional HTTP method, if null the current request method will be used (e.g, GET, POST).

Return:

self - Returns the instance request class.


removeField

Remove a specific field from the request body for the given HTTP method.

public function removeField(string $field, ?string $method = null): self

Parameters:

ParameterTypeDescription
$fieldstringThe name of the field to remove.
$methodstring|nullOptional HTTP method, if null the current request method will be used (e.g, GET, POST).

Return:

self - Returns the instance request class.


input

Get a field value from Any valid incoming HTTP request method.

If $method is provided, it checks field in the specified HTTP method, otherwise it use the current request method.

public function input(string $field, mixed $default = null, ?string $method = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe input field name to retrieve the value value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).
$methodstring|nullOptional HTTP method to retrieve valid from (default: null as ANY).

Return:

mixed - Return the value from HTTP request method body based on field name or default value.

Example:

$username = $request->input('username');

getGet

Get a field value from HTTP GET request method. Use getParsedBody() to retrieve the complete parsed body.

public function getGet(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getPost

Get a field value from HTTP POST request method. Use getParsedBody() to retrieve the complete parsed body.

public function getPost(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getPut

Get a value from the PUT request. Use getParsedBody() to retrieve the complete parsed body.

public function getPut(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getOptions

Get a value from the OPTIONS request. Use getParsedBody() to retrieve the complete parsed body.

public function getOptions(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getPatch

Get a value from the PATCH request method. Use getParsedBody() to retrieve the complete parsed body.

public function getPatch(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getHead

Get a value from the HEAD request method. Use getParsedBody() to retrieve the complete parsed body.

public function getHead(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getConnect

Get a value from the CONNECT request method. Use getParsedBody() to retrieve the complete parsed body.

public function getConnect(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getTrace

Get a value from the TRACE request method. Use getParsedBody() to retrieve the complete parsed body.

public function getTrace(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getPropfind

Get a value from the PROPFIND request method. Use getParsedBody() to retrieve the complete parsed body.

public function getPropfind(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getMkcol

Get a value from the MKCOL request method. Use getParsedBody() to retrieve the complete parsed body.

public function getMkcol(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getCopy

Get a value from the COPY request method. Use getParsedBody() to retrieve the complete parsed body.

public function getCopy(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getMove

Get a value from the MOVE request method. Use getParsedBody() to retrieve the complete parsed body.

public function getMove(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getLock

Get a value from the LOCK request method. Use getParsedBody() to retrieve the complete parsed body.

public function getLock(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getUnlock

Get a value from the UNLOCK request method. Use getParsedBody() to retrieve the complete parsed body.

public function getUnlock(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from HTTP request method body based on field name.


getAny

Get a value from the ANY incoming HTTP request method.

public function getAny(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringThe field key to retrieve the value from.
$defaultmixedAn optional default value to return if the field is not found (default: null).

Return:

mixed - Return the value from current HTTP request method, based on field name.

Throws:

Example:

This can be useful for debugging, when you are sure that all request must include a specific field.

try{
    $this->doSomething();
}catch(Exception $e){
    Logger::error(
        'Error while processing: ' . $e->getMessage(), 
        [
            'device_id' => $this->request->getAny('device')
        ]
    );
}

getArray

Get a value from the request body as an array.

public function getArray(string $field, array $default = [], ?string $method = null): array

Parameters:

ParameterTypeDescription
$fieldstringThe request body field name to return.
$defaultarray<array-key, mixed>Optional default value to return (default: []).
$methodstring|nullOptional HTTP request method, if null current request method will be used (e.g, GET, POST, etc..).

Return:

array<array-key, mixed> - Return array of HTTP request method key values.


getCookie

Retrieves the instance of cookie jar containing the cookies from the request headers.

This method parses the Cookie header, identifies session cookies, and initializes a cookie jar. It supports session-specific configurations and handles both session and non-session cookies.

public function getCookie(): CookieJarInterface

Return:

Luminova\Interface\CookieJarInterface - Return the cookie jar instance populated with parsed cookies.

Example:

print_r($request->getCookie()->getCookieNames());

getBody

Get the request body as a PSR-7 stream.

Converts the request body into a StreamInterface. If the body is already a StreamInterface, it is returned as-is. Otherwise, the array body is encoded as an RFC3986-compliant query string.

public function getBody(): StreamInterface

Return:

Psr\Http\Message\StreamInterface - Returns request body as stream.

Throws:


getParsedBody

Get the entire request body as an array or JSON object.

public function getParsedBody(bool $asObject = false): array|object

Parameters:

ParameterTypeDescription
$asObjectboolWhether to return an array or a JSON object (default: false).

Return:

array<string,mixed>|object{key:value} - Return the request body as an array or JSON object.


getCsrfToken

Retrieve the CSRF token from the current request.

This method checks incoming request data (POST, PUT, DELETE, or GET) for a field named csrf_token and returns its value if present.

public function getCsrfToken(): ?string

Return:

string|null - Returns the CSRF token string if found, otherwise null.


getUtmParam

Get UTM parameter data from the request.

public function getUtmParam(?string $param = null, bool $persist = false): ?UTMClient

Parameters:

ParameterTypeDescription
$paramstring|nullThe specific UTM parameter to retrieve (e.g., utm_source, utm_medium).
If null, returns all standard UTM param.
$persistboolWhether to persist UTM data in configured storage (default: false).

Return:

\Luminova\Http\Attribution\UTMClient|null - Returns an instance of UTMClient containing the UTM data, or null if not available.


getFields

Retrieve an array of request fields (keys).

This method extract all keys from request body.

public function getFields(): array

Return:

array<array-key, mixed> - Return an array list request fields.


getFile

Get an uploaded file instance or a generator yielding file instances for multiple files.

public function getFile(string $name, ?int $index = null): Generator|UploadedFileInterface|null

Parameters:

ParameterTypeDescription
$namestringThe file input field name.
$indexint|nullOptional file index for multiple files. If null, all files will be returned (default: null).

Return:

Generator<int,UploadedFileInterface,void,void>|UploadedFileInterface|null - Returns an uploaded File instance, a generator yielding Luminova\Http\File instances for multiple files, or null if the input name was not found.

See Also:

To learn more about File Upload Object, or handle file uploading File Uploader, refer to the documentations.

Process File Object:

Handle file upload based on multiple files or single file.

use Luminova\Http\File;
use Luminova\Http\Uploader;
use function Luminova\Funcs\root;

$images = $request->getFiles('images');
$config = [
    'upload_path' => root('writeable/storages/foo/'),
    'if_existed' => File::IF_EXIST_OVERWRITE
];

// Multiple files
if ($images instanceof \Generator) {
    foreach ($images as $index => $image) {
        if($image->valid()){
            $image->setConfig($config);
            $status = Uploader::upload($image);
        }

        echo $image-->getMessage();
    }
    return;
} 

// For single file
if ($images instanceof File) {
    if($images->valid()){
        $images->setConfig($config);
        $status = Uploader::upload($images);
    }

    echo $images-->getMessage();
}

getFiles

Get raw array of original uploaded file information without any modification.

/**
 * @return UploadedFileInterface[]
 */
public function getFiles(): array

Return:

Psr\Http\Message\UploadedFileInterface[] - Return an array containing uploaded files information.


getMethod

Retrieves actual HTTP method if provided by the client.

public function getMethod(): string

Return:

string - Return the HTTP method in uppercase.


getAnyMethod

Retrieves the HTTP method of the request or method overrides.

If the original request method is POST and a method override is present (e.g., via _method field or X-HTTP-Method-Override header), the overridden method is returned instead. This is useful for supporting RESTful methods when method is spoofed from POST requests.

public function getAnyMethod(): string

Return:

string - Return the HTTP method or override method.


getMethodOverride

Retrieves the HTTP method override if provided by the client.

This method checks for the "X-HTTP-Method-Override" value first in the request headers. If found, the override method is returned in uppercase.

public function getMethodOverride(): ?string

Return:

string|null - Return the overridden HTTP method in uppercase, or null if not set.


getBoundary

Extract the boundary from the Content-Type header.

public function getBoundary(): ?string

Return:

string|null - Returns the boundary string or null if not found.


getFromMultipart

Parses a multipart/form-data string into an associative array with form fields and file data.

/**
 * @return array{param:array, files:array}
 */
public static function getFromMultipart(string $data, string $boundary): array

Parameters:

ParameterTypeDescription
$datastringThe raw multipart form data content.
$boundarystringThe boundary string used to separate form data parts.

Return:

array{param:array,files:array} - Return an array containing two keys params and files.

  • params - Associative array of form field names and values
  • files - Associative array of files with metadata and binary content

getContentType

Get the request content type.

public function getContentType(): string

Return:

string - Return the request content type or blank string if not available.


getAuth

Get HTTP request header authorization from (e.g, HTTP_AUTHORIZATION, Authorization or REDIRECT_HTTP_AUTHORIZATION).

public function getAuth(): ?string

Return:

string|null - Return the authorization header value or null if no authorization header was sent.


getQuery

Retrieve a query parameter from the request URL.

This method is used to access query parameters sent in the URL (e.g., /path?param=value) regardless of the request method (GET, POST, etc).

Note: For a non-GET request, the framework merges URL query parameters into parsed input as fallbacks. An explicitly supplied stream body takes a separate parsing path. Use getQuery() to read a URL query parameter directly in either case.

public function getQuery(string $field, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$fieldstringQuery parameter name.
$defaultmixedThe default value to return if the parameter does not exist (default: null).

Return:

mixed - Returns the named query value or the supplied default. Use getQueryString() for the full encoded query string.


getQueryParams

Get request URL query parameters as an associative array using the parameter name as key.

public function getQueryParams(): array

Return:

array<string,mixed> - Return the request URL query parameters as an array.


getUrl

Get the full URL of the current request.

This method returns the complete URL, including the protocol (e.g., http or https), the domain name, the path, and any query string parameters.

public function getUrl(bool $withPort = false): string

Parameters:

ParameterTypeDescription
$withPortboolWhether to return hostname with port (default: false).

Return:

string - Return the full URL of the request.


getUri

Get the URI (path and query string) of the current request (e.g, https://example.com/foo/bar?query=123).

This method returns only the URI, which includes the path and query string, but excludes the protocol and domain name.

public function getUri(): UriInterface;

Return:

Psr\Http\Message\UriInterface - Return the URI of the request (host, path and query string).


getPaths

Get current request URL path information.

public function getPaths(): string

Return:

string - Return the request URL paths.


getRequestUri

Returns un-decoded request URI, path and query string.

public function getRequestUri(): string

Return:

string - Return the raw request URI (i.e. URI not decoded).


getHost

Get current request hostname without port, if allowed host is set it will check if host is in allowed list or patterns.

public function getHost(bool $exception = false): ?string

Parameters:

ParameterTypeDescription
$exceptionboolWhether to throw an exception if invalid host or not allowed host (default: false).

Return:

string|null - Returns the validated hostname without its port, or null if no valid host is available and exceptions are disabled.

Throws:


getHostname

Get current request hostname with port if port is available.If allowed host is set it will check if host is in allowed list or patterns.

public function getHostname(
    bool $exception = false,
    bool $withPort = true,
    bool $validateHost = true
): ?string

Parameters:

ParameterTypeDescription
$exceptionboolWhether to throw an exception if invalid host or not allowed host (default: false).
$withPortboolWhether to return hostname with port (default: true).
$validateHostboolCheck the hostname against configured trusted hosts (default: true).

Return:

string|null - Returns the hostname and optional port, or null if the host is invalid and exceptions are disabled.

Throws:


getOrigin

Get the request origin domain, if the list of trusted origin domains are specified, it will check if the origin is a trusted origin domain.

public function getOrigin(bool $validate = false): ?string

Parameters:

ParameterTypeDescription
$validateboolCheck the origin against trusted origins when configured.

Return:

string|null - Returns the origin header by default. When checking a configured trusted-origin list, returns the matched domain or null.


getPort

Get the request origin port from X_FORWARDED_PORT or SERVER_PORT if available.

public function getPort(): int

Return:

int - Return the port number, otherwise default to 443 secured or 80 for insecure.

Check if X-Forwarded-Port header exists and use if available.If not available check for server-port header if also not available return default port.


getScheme

Gets the request scheme name.

public function getScheme(): string

Return:

string - Return request scheme, if secured return https otherwise http.


getProtocol

Gets the request server protocol name and version (e.g: HTTP/1.1).

public function getProtocol(): string

Return:

string - Return Request protocol name and version, if available, otherwise default is return HTTP/1.1.


getProtocolVersion

Get the HTTP protocol version used in the request. (e.g: 1.1).

public function getProtocolVersion(): string

Return:

string - Returns the HTTP protocol version (e.g., 1.1, 2.0).


getBrowser

Get the request browser name and platform from user-agent information.

public function getBrowser(): string

Return:

string - Return browser name and platform.


getUserAgent

Get request browser user-agent information.

The User Agent string is driven from request header (HTTP_USER_AGENT).

public function getUserAgent(): UserAgent

Return:

Luminova\Http\UserAgent - Return instance user-agent class containing browser information.

For more information see UserAgent Class, documentation.


getRequestTarget

Retrieve the request target (e.g., path, query string).

public function getRequestTarget(): string

Return:

string - Returns the request-target as it will appear in the HTTP request line.


getServerParams

Retrieve server parameters (e.g., $_SERVER values).

public function getServerParams(): array

Return:

array<array-key, mixed> - Returns an array of server parameters.


getCookieParams

Retrieve cookies sent with the request.

public function getCookieParams(): array

Return:

array<array-key, mixed> - Returns an array of cookies (name => value).


getHeaders

Retrieve all HTTP headers.

public function getHeaders(): array

Return:

array<array-key, mixed> - Returns an array of headers (name => array of values).


getHeader

Retrieve a specific HTTP header.

public function getHeader(string $name): array

Parameters:

ParameterTypeDescription
$namestringHeader name (case-insensitive).

Return:

array<array-key, mixed> - Returns an array of values for the header, or empty array if missing.


getHeaderLine

Retrieve a specific HTTP header as a comma-separated string.

public function getHeaderLine(string $header): string

Parameters:

ParameterTypeDescription
$headerstringHeader name (case-insensitive).

Return:

string - Returns concatenated header values, or empty string if missing.


isGet

Check if the request method is GET.

public function isGet(): bool

Return:

bool - Returns true if the request method is GET, false otherwise.


isPost

Check if the request method is POST.

public function isPost(): bool

Return:

bool - Returns true if the request method is POST, false otherwise.


isMethod

Check if the request method is the provided method.

public function isMethod(string|array $method = 'GET'): bool

Parameters:

ParameterTypeDescription
$methodstring\|string[]The method or methods to check (e.g, POST, GET).

Return:

bool - Returns true if the request method matches the provided method, false otherwise.


isAuth

Check if the Authorization header matches the specified type.

public function isAuth(string $scheme = 'Bearer'): bool

Parameters:

ParameterTypeDescription
$schemestringThe expected type of authorization (e.g., 'Bearer', 'Basic').

Return:

bool - Returns true if the Authorization header matches the specified type, otherwise false.


Return:

bool - Return true if the request was made from the command line.


isSecure

Check if the current request connection is secure.

public function isSecure(): bool

Return:

bool - Return true if the connection is secure false otherwise.


isProxy

Checks if the request is routed through a proxy server by inspecting various proxy-related headers.

public function isProxy(): bool

Return:

bool - Returns true if the request is likely from proxy, false otherwise.


isAjax

Check if request is ajax request, see if a request contains the HTTP_X_REQUESTED_WITH header.

public function isAjax(): bool

Return:

bool - Return true if request is ajax request, false otherwise


isApi

Check if the request URL indicates an API request endpoint.This method checks if the URL path prefix matched any of /api or public/api or your custom defined API URL prefix.

public function isApi(?bool $validateAjaxAsApi = null): bool

Parameters:

ParameterTypeDescription
$validateAjaxAsApibool\|nullTreat AJAX requests as API requests. Null uses the application setting.

Return:

bool - Returns true if the URL indicates an API endpoint, false otherwise.


isSameOrigin

Check if the request origin matches the current application host.

public function isSameOrigin(bool $subdomains = false, bool $strict = false): bool

Parameters:

ParameterTypeDescription
$subdomainsboolWhether to consider sub-domains or not (default: false).
$strictboolWhen set to true, if request origin is empty it checks for referer if also empty return false (default: false).
If set to false, it checks for only the request origin is empty it returns true without further validation.

Return:

bool - Returns true if the request origin matches the current host, false otherwise.


isTrusted

Validates if the given (hostname, origin, proxy ip or subnet) matches any of the trusted patterns.

public static function isTrusted(string $input, string $context = 'hostname'): bool

Parameters:

ParameterTypeDescription
$inputstringThe domain, origin or IP address to check (e.g, example.com, 192.168.0.1).
$contextstringThe context to check input for (e.g, hostname).

Return:

bool - Return true if the input is trusted, false otherwise.

Throws:

Supported Context:

  • hostname - Validates a host name.
  • origin - Validates an origin hostname.
  • proxy Validates an IP address or proxy.

Note: This will consider the defined configuration in App\Config\Security during validation.


isTrustedProxy

Check whether this request origin IP address is from a trusted proxy.

public function isTrustedProxy(): bool

Return:

bool - Return true if the request origin IP address is trusted false otherwise.


isTrustedOrigin

Check whether this request origin is from a trusted origins.

public function isTrustedOrigin(): bool

Return:

bool - Return true if the request origin is trusted false otherwise.


hasField

Check if a specific field exists in the request body for the given HTTP method.

public function hasField(string $field, ?string $method = null): bool

Parameters:

ParameterTypeDescription
$fieldstringThe name of the field to check.
$methodstring|nullOptional HTTP method, if null the current request method will be used (e.g, GET, POST).

Return:

bool - Returns true if the field exists for the given method; otherwise, false.


hasHeader

Check if a specific HTTP header is present.

public function hasHeader(string $name): bool

Parameters:

ParameterTypeDescription
$namestringHeader name (case-insensitive).

Return:

bool - Returns true if header exists, false otherwise.


withStatus

Return a new instance with the specified HTTP status code and reason phrase.

public function withStatus(int $code, string $reasonPhrase = ''): static

Parameters:

ParameterTypeDescription
$codeintHTTP status code.
$reasonPhrasestringOptional reason phrase; defaults to standard if empty.

Return:

static - Returns a new request instance with updated status.

Throws:


withoutHeader

Return a new instance without a specific HTTP header.

public function withoutHeader(string $name): static

Parameters:

ParameterTypeDescription
$namestringHeader name to remove.

Return:

static - Returns a new request instance with the header removed.


withHeader

Return a new instance with a specific HTTP header.

/**
 * @param string|array<array-key, mixed> $value
 */
public function withHeader(string $name, $value): static

Parameters:

ParameterTypeDescription
$namestringHeader name.
$valuestring|arrayHeader value(s).

Return:

static - Returns a new request instance with updated header.


withProtocolVersion

Return a new instance with a specific HTTP protocol version.

public function withProtocolVersion(string $version): static

Parameters:

ParameterTypeDescription
$versionstringProtocol version (e.g., "1.1", "2.0").

Return:

static - Returns a new request instance with updated protocol version.


withAddedHeader

Return a new instance with an additional HTTP header value.

/**
 * @param string|array<array-key, mixed> $value
 */
public function withAddedHeader(string $name, $value): static

Parameters:

ParameterTypeDescription
$namestringHeader name.
$valuestring|arrayHeader value(s) to append.

Return:

static - Returns a new request instance with added header value.


withBody

Return a new instance with the provided message body.

public function withBody(StreamInterface $body): static

Parameters:

ParameterTypeDescription
$body\Psr\Http\Message\StreamInterfaceStream representing the request body.

Return:

static - Returns a new request instance with updated body.


withMethod

Return a new instance with a specific HTTP method.

public function withMethod(string $method): static

Parameters:

ParameterTypeDescription
$methodstringHTTP method (e.g., GET, POST).

Return:

static - Returns a new request instance with updated method.

Throws:


withRequestTarget

Return a new instance with a specific request target.

public function withRequestTarget(string $requestTarget): static

Parameters:

ParameterTypeDescription
$requestTargetstringThe request-target (path and query).

Return:

static - Returns a new request instance with updated request target.


withUri

Return a new instance with a specific URI.

public function withUri(UriInterface $uri, bool $preserveHost = false): static

Parameters:

ParameterTypeDescription
$uri\Psr\Http\Message\UriInterfaceThe URI to use.
$preserveHostboolWhether to preserve the original Host header.

Return:

static - Returns a new request instance with updated URI.


capture

Create a request from the active PHP request context. The default mode reuses the shared instance.

public static function capture(bool $shared = true): self

Parameters:

ParameterTypeDescription
$sharedboolReuse the shared request when true.

Return:

self - Returns the captured request.


getQueryString

Encode the parsed query parameters using RFC 3986 encoding.

public function getQueryString(): string

Return:

string - Returns the query string without a leading question mark.


getJsonrpc

Read a JSON-RPC payload from the parsed POST body. This checks the version marker.

public function getJsonrpc(?string $version = '2.0'): ?object

Parameters:

ParameterTypeDescription
$versionstring\|nullRequired JSON-RPC version. Null accepts any string version marker.

Return:

object|null - Returns the payload as an object, or null when the method, payload, or version check fails.


getRaw

Read the raw body from php://input.

public function getRaw(): ?string

Return:

string|null - Returns the raw input, or null if PHP returns a falsy value.


toArray

Get the parsed request body as an array.

public function toArray(): array

Return:

array<array-key,mixed> - Returns the parsed body fields.


getClientIp

Resolve the client address through the framework IP utility.

public function getClientIp(): string

Return:

string - Returns the detected address or the IP utility fallback.


getClientIps

Collect the client address candidates through the framework IP utility.

public function getClientIps(): array

Return:

string[] - Returns the candidates or a list containing the fallback address.


setCookie

Select a cookie by name on the request’s cookie jar.

public function setCookie(string $name): self

Parameters:

ParameterTypeDescription
$namestringCookie name to select.

Return:

self - Returns the current request.


getAuthorization

Read the Authorization header or its redirected server equivalent and trim whitespace.

public function getAuthorization(): ?string

Return:

string|null - Returns the authorization string or null when unavailable.


getReferer

Read and reconstruct the referrer URL from its scheme, host, path, and optional query.

public function getReferer(bool $sameOrigin = true): ?string

Parameters:

ParameterTypeDescription
$sameOriginboolRequire a same-origin referrer when true.

Return:

string|null - Returns the referrer URL if it passes the checks, or null.


hasQuery

Check whether the query parameter map contains the named key, including a key with a null value.

public function hasQuery(string $name): bool

Parameters:

ParameterTypeDescription
$namestringQuery parameter name.

Return:

bool - Returns true if the key exists.


hasFile

Check for a named entry in the supplied file map or $_FILES.

public function hasFile(string $name): bool

Parameters:

ParameterTypeDescription
$namestringFile field name.

Return:

bool - Returns true if the field exists. Use the file object to check upload status.


isQuery

Check the HTTP request method.

public function isQuery(): bool

Return:

bool - Returns true for the QUERY method.


isPjax

Inspect the X-PJAX header.

public function isPjax(): bool

Return:

bool - Returns true for boolean true or the strings true and 1.


isPrefetch

Inspect Purpose, X-Moz, or X-Requested-With, in that order.

public function isPrefetch(): bool

Return:

bool - Returns true when the selected header equals prefetch, ignoring case.


isXmlHttpRequest

Inspect the X-Requested-With header.

public function isXmlHttpRequest(): bool

Return:

bool - Returns true when the header equals XMLHttpRequest, ignoring case.


isTrustedHost

Check the request hostname against the configured host trust rules.

public function isTrustedHost(): bool

Return:

bool - Returns the hostname trust check result.


isGraphQL

Check the parsed request body for a query string that resembles GraphQL. It looks for parentheses and braces and rejects a query string that is itself valid JSON.

public function isGraphQL(): bool

Return:

bool - Returns true when the query passes the heuristic.


isBodySupported

Check whether the framework treats an HTTP method as supporting a request body.

public function isBodySupported(?string $method = null): bool

Parameters:

ParameterTypeDescription
$methodstring\|nullOptional HTTP method. Null checks the current request method.

Return:

bool - Returns true if the method is in the framework’s body-capable method set.


jsonSerialize

Supply the parsed request body when encoding the request as JSON.

public function jsonSerialize(): mixed

Return:

array<array-key,mixed> - Returns the parsed body fields.


__toArray

Provide the parsed request body through the framework array conversion interface.

public function __toArray(): array

Return:

array<array-key,mixed> - Returns the parsed body fields.