Pickles Framework Documentation

Request
in package

Class Request

Encapsulates the HTTP request data retrieved from the Server implementation. Provides access to URI, method, POST data, and query parameters.

Table of Contents

Properties

$data  : array<string, mixed>
POST data from the request.
$files  : array<string, File>
Array that contains the Uploaded files.
$headers  : array<string, string>
Request headers.
$method  : HttpMethod
The HTTP method of the request.
$queryParams  : array<string, string>
Query parameters from the request URI.
$route  : Route
Route match by URI
$uri  : string
The request URI path.

Methods

data()  : array<string|int, mixed>|string|null
Retrieves a specific item from the POST data or returns all POST data.
files()  : File|null
Retrieves a file from the uploaded files array.
headers()  : string|array<string|int, mixed>|null
Get all request headers or a specific header.
method()  : HttpMethod
Get the HTTP method used in the request.
queryParams()  : string|array<string|int, string>|null
Get all query parameters
route()  : Route
Get route match by URI of this request.
routeParams()  : string|array<string|int, string>|null
Get all route params
setData()  : self
Set POST data
setFiles()  : self
Set uploaded files.
setHeaders()  : self
Set Request headers
setMethod()  : self
Set the HTTP method of the request.
setQueryParams()  : self
Set query parameters.
setRoute()  : self
Set route for this request.
setUri()  : self
Set request URI.
uri()  : string
Get the request URI path.
validate()  : array<string, mixed>
Validates the request data against the provided validation rules.

Properties

$data

POST data from the request.

protected array<string, mixed> $data

$files

Array that contains the Uploaded files.

protected array<string, File> $files = []

$headers

Request headers.

protected array<string, string> $headers = []

$queryParams

Query parameters from the request URI.

protected array<string, string> $queryParams

$uri

The request URI path.

protected string $uri

Methods

data()

Retrieves a specific item from the POST data or returns all POST data.

public data([string|null $key = null ]) : array<string|int, mixed>|string|null

If no key is provided, the entire POST data array will be returned. If a key is provided but does not exist in the data, null will be returned.

Parameters
$key : string|null = null

The data key to retrieve, or null to get all data.

Tags
throws
InvalidArgumentException

If the provided key is not a string.

Return values
array<string|int, mixed>|string|null

The entire data array, a specific value, or null if the key is not set.

files()

Retrieves a file from the uploaded files array.

public files([string|null $key = null ]) : File|null
Parameters
$key : string|null = null

The key of the file to retrieve. If null, no specific file is targeted.

Return values
File|null

The file object associated with the given key, or null if the key does not exist.

headers()

Get all request headers or a specific header.

public headers([string|null $key = null ]) : string|array<string|int, mixed>|null
Parameters
$key : string|null = null
Tags
@return

array<string,

Return values
string|array<string|int, mixed>|null

queryParams()

Get all query parameters

public queryParams([string|null $key = null ]) : string|array<string|int, string>|null
Parameters
$key : string|null = null
Tags
throws
InvalidArgumentException

when $key is not null or string

Return values
string|array<string|int, string>|null

route()

Get route match by URI of this request.

public route() : Route
Return values
Route

routeParams()

Get all route params

public routeParams([string|null $key = null ]) : string|array<string|int, string>|null
Parameters
$key : string|null = null
Tags
throws
InvalidArgumentException

when $key is not a string

Return values
string|array<string|int, string>|null

setData()

Set POST data

public setData(array<string|int, mixed> $data) : self
Parameters
$data : array<string|int, mixed>
Return values
self

setFiles()

Set uploaded files.

public setFiles(array<string, File$files) : self
Parameters
$files : array<string, File>
Return values
self

setHeaders()

Set Request headers

public setHeaders(array<string, string> $headers) : self
Parameters
$headers : array<string, string>
Return values
self

setMethod()

Set the HTTP method of the request.

public setMethod(HttpMethod $method) : self
Parameters
$method : HttpMethod

The HTTP method of the request.

Return values
self

setQueryParams()

Set query parameters.

public setQueryParams(array<string, string> $queryParams) : self
Parameters
$queryParams : array<string, string>
Return values
self

setRoute()

Set route for this request.

public setRoute(Route $route) : self
Parameters
$route : Route
Return values
self

setUri()

Set request URI.

public setUri(string $uri) : self
Parameters
$uri : string

The request URI path.

Return values
self

uri()

Get the request URI path.

public uri() : string
Return values
string

validate()

Validates the request data against the provided validation rules.

public validate(array<string, mixed> $validationRules[, array<string, string> $messages = [] ]) : array<string, mixed>
Parameters
$validationRules : array<string, mixed>

An associative array of validation rules where the key is the field name and the value is the validation rule(s) to apply.

$messages : array<string, string> = []

Optional. An associative array of custom error messages where the key is the rule or field name and the value is the custom message.

Return values
array<string, mixed>

An array containing the validation results, including any errors encountered.


        
On this page

Search results