Menu

## Request extends AbstractRequest
in package
implements RequestInterface

Request.php : 18

Class for handling various variables from the server.

##### Tags

see
  https://www.kotchasan.com/

### Interfaces, Classes and Traits

RequestInterface
  Representation of an outgoing, client-side request.

### Table of Contents

$headers : array<string|int, mixed>
$method : string|null
$protocol : string
$requestTarget : string|null
$stream : StreamInterface
$uri : Uri|null
$attributes : array<string|int, mixed>
$cookieParams : array<string|int, mixed>
  $_COOKIE
$parsedBody : array<string|int, mixed>
  $_POST
$queryParams : array<string|int, mixed>
  $_GET
$serverParams : array<string|int, mixed>
  $_SERVER
$uploadedFiles : Files
__construct() : mixed
  Initializes the class.
cookie() : InputItem|Inputs
  Reads a value from the COOKIE variable.
createToken() : string
  Generates a token.
createUriWithGet() : Uri
  Create a class from a link and merge values from $_GET
createUriWithGlobals() : Uri
  Create a class from a link and merge values from $_GET and $_POST
createUriWithPost() : Uri
  Create a class from a link and merge values from $_POST
filterRequestKey() : array<string|int, mixed>
  Filters the keys of the requests.
get() : InputItem|Inputs
  Reads a value from the GET variable.
getAcceptableLanguages() : array<string|int, mixed>
  Returns the list of acceptable languages from the HTTP header.
getAttribute() : mixed
  Retrieves the attribute with the given name.
getAttributes() : array<string|int, mixed>
  Retrieves the attributes.
getBody() : StreamInterface
  Read the stream.
getClientIp() : array<string|int, mixed>|null
  Retrieves the parsed body parameters, if any.
getCookieParams() : array<string|int, mixed>
  Get values from the $_COOKIE variable.
getHeader() : array<string|int, string>
  Get the specified header as an array.
getHeaderLine() : string
  Get the specified header as a string.
getHeaders() : array<string|int, mixed>
  Get all the headers.
getMethod() : string
  Get the HTTP method
getParsedBody() : null|array<string|int, mixed>|object
  Get values from the $_POST variable.
getProtocolVersion() : string
  Get the protocol version of the message.
getQueryParams() : null|array<string|int, mixed>|object
  Get values from the $_GET variable.
getRequestTarget() : string
  Get the request target
getServerParams() : array<string|int, mixed>
  Get values from the $_SERVER variable.
getUploadedFiles() : Files
  Get uploaded files from $_FILES.
getUri() : Uri
  Get the URI
globals() : InputItem|Inputs
  Read values from the GLOBALS variables ($_POST, $_GET, $_SESSION, $_COOKIE) according to the specified keys.
hasHeader() : bool
  Check if a header exists.
initSession() : bool
  Initialize session.
isAjax() : bool
  Check if the request is made via Ajax.
isReferer() : bool
  Check if the referer is from the same website.
isSafe() : bool
  Check the token from the form and validate the referer.
map() : mixed
  Merge arrays $_GET and $_POST into a single data array
post() : InputItem|Inputs
  Read a value from the $_POST variable.
removeToken() : mixed
  Remove the token.
request() : InputItem|Inputs
  Read a value from the $_POST, $_GET, $_COOKIE (optional) variables in order.
server() : mixed
  Read a value from the $_SERVER variable.
session() : InputItem|Inputs
  Read a value from the $_SESSION variable.
setSession() : static
  Set the value of $_SESSION variable.
withAddedHeader() : static
  Add a new header.
withAttribute() : static
  Set the value of attributes.
withBody() : static
  Set the message body.
withCookieParams() : static
  Set the value of cookieParams.
withHeader() : static
  Set a header, replacing any existing values.
withHeaders() : static
  Set multiple headers, replacing any existing values.
withMethod() : static
  Set the HTTP method
withoutAttribute() : static
  Removes attributes.
withoutHeader() : static
  Remove a header.
withParsedBody() : static
  Set the value of parsedBody.
withProtocolVersion() : static
  Set the protocol version of the message.
withQueryParams() : static
  Set the value of queryParams.
withRequestTarget() : static
  Set the request target
withUploadedFiles() : static
  Set the value of uploadedFiles.
withUri() : static
  Set the URI
filterHeader() : mixed
  Check the validity of a header.
getRequestHeaders() : array<string|int, mixed>
  Function to retrieve HTTP headers.
createInputItem() : InputItem|Inputs
  Reads a value from the $source.

### Properties

#### $headers

AbstractMessage.php : 29
`protected array<string|int, mixed> $headers = []`

The headers of the message.

#### $method

AbstractRequest.php : 23
`protected string|null $method = null`

The HTTP method

#### $protocol

AbstractMessage.php : 34
`protected string $protocol = '1.1'`

The protocol version of the message.

#### $requestTarget

AbstractRequest.php : 28
`protected string|null $requestTarget`

The request target

#### $stream

AbstractMessage.php : 39
`protected StreamInterface $stream`

The body of the message.

#### $uri

AbstractRequest.php : 33
`protected Uri|null $uri`

The URI

#### $attributes

Request.php : 23
`private array<string|int, mixed> $attributes = []`

#### $cookieParams

Request.php : 30

$_COOKIE

`private array<string|int, mixed> $cookieParams`

#### $parsedBody

Request.php : 37

$_POST

`private array<string|int, mixed> $parsedBody`

#### $queryParams

Request.php : 44

$_GET

`private array<string|int, mixed> $queryParams`

#### $serverParams

Request.php : 51

$_SERVER

`private array<string|int, mixed> $serverParams`

#### $uploadedFiles

Request.php : 56
`private Files $uploadedFiles`

### Methods

#### __construct()

AbstractMessage.php : 46

Initializes the class.

`public __construct([bool $withHeader = false ]) : mixed`

##### Parameters

$withHeader : bool = false

  Whether to include the HTTP header or not. Default is false.

##### Return values

mixed —

#### cookie()

Request.php : 67

Reads a value from the COOKIE variable.

`public cookie(string $name[, mixed $default = '' ]) : InputItem|Inputs`

Returns an InputItem or a collection of InputItem.

##### Parameters

$name : string

  The name of the variable.

$default : mixed = ''

  The default value if the variable is not found.

##### Return values

InputItem|Inputs —

#### createToken()

Request.php : 77

Generates a token.

`public createToken() : string`

##### Return values

string —

The generated token.

#### createUriWithGet()

AbstractRequest.php : 43

Create a class from a link and merge values from $_GET

`public static createUriWithGet([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri`

##### Parameters

$uri : string = 'index.php'

  The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

  An array of keys from $_GET to exclude from the URL

##### Return values

Uri —

#### createUriWithGlobals()

AbstractRequest.php : 61

Create a class from a link and merge values from $_GET and $_POST

`public createUriWithGlobals([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri`

##### Parameters

$uri : string = 'index.php'

  The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

  An array of keys from $_GET and $_POST to exclude from the URL

##### Return values

Uri —

#### createUriWithPost()

AbstractRequest.php : 80

Create a class from a link and merge values from $_POST

`public static createUriWithPost([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri`

##### Parameters

$uri : string = 'index.php'

  The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

  An array of keys from $_POST to exclude from the URL

##### Return values

Uri —

#### filterRequestKey()

Request.php : 618

Filters the keys of the requests.

`public static filterRequestKey(array<string|int, mixed> $source) : array<string|int, mixed>`

##### Parameters

$source : array<string|int, mixed>

  The source array.

##### Return values

array<string|int, mixed> —

The filtered array.

#### get()

Request.php : 97

Reads a value from the GET variable.

`public get(string $name[, mixed $default = null ][, string $cookie = null ]) : InputItem|Inputs`

Returns an InputItem or a collection of InputItem.

##### Parameters

$name : string

  The name of the variable.

$default : mixed = null

  The default value if the variable is not found.

$cookie : string = null

  null (default) to not read from the cookie, string specifying the cookie name to read from.

##### Return values

InputItem|Inputs —

#### getAcceptableLanguages()

Request.php : 111

Returns the list of acceptable languages from the HTTP header.

`public getAcceptableLanguages() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

The list of acceptable languages.

#### getAttribute()

Request.php : 145

Retrieves the attribute with the given name.

`public getAttribute(string $name[, mixed $default = null ]) : mixed`

##### Parameters

$name : string

  The attribute name.

$default : mixed = null

  The default value if the attribute is not found.

##### Return values

mixed —

The attribute value.

#### getAttributes()

Request.php : 155

Retrieves the attributes.

`public getAttributes() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

The attributes.

#### getBody()

Request.php : 241

Read the stream.

`public getBody() : StreamInterface`

##### Return values

StreamInterface —

#### getClientIp()

Request.php : 165

Retrieves the parsed body parameters, if any.

`public getClientIp() : array<string|int, mixed>|null`

##### Return values

array<string|int, mixed>|null —

The parsed body parameters.

#### getCookieParams()

Request.php : 185

Get values from the $_COOKIE variable.

`public getCookieParams() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

#### getHeader()

AbstractMessage.php : 70

Get the specified header as an array.

`public getHeader(string $name) : array<string|int, string>`

##### Parameters

$name : string

  The name of the header.

##### Return values

array<string|int, string> —

The values of the header as an array, or an empty array if not found.

#### getHeaderLine()

AbstractMessage.php : 82

Get the specified header as a string.

`public getHeaderLine(string $name) : string`

##### Parameters

$name : string

  The name of the header.

##### Return values

string —

The concatenated values of the header, separated by commas, or an empty string if not found.

#### getHeaders()

AbstractMessage.php : 93

Get all the headers.

`public getHeaders() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

The headers of the message.

#### getMethod()

AbstractRequest.php : 95

Get the HTTP method

`public getMethod() : string`

##### Return values

string —

The request method

#### getParsedBody()

Request.php : 198

Get values from the $_POST variable.

`public getParsedBody() : null|array<string|int, mixed>|object`

##### Return values

null|array<string|int, mixed>|object —

#### getProtocolVersion()

AbstractMessage.php : 103

Get the protocol version of the message.

`public getProtocolVersion() : string`

##### Return values

string —

The protocol version.

#### getQueryParams()

Request.php : 215

Get values from the $_GET variable.

`public getQueryParams() : null|array<string|int, mixed>|object`

##### Return values

null|array<string|int, mixed>|object —

#### getRequestTarget()

AbstractRequest.php : 111

Get the request target

`public getRequestTarget() : string`

##### Return values

string —

The request target

#### getServerParams()

Request.php : 228

Get values from the $_SERVER variable.

`public getServerParams() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

#### getUploadedFiles()

Request.php : 251

Get uploaded files from $_FILES.

`public getUploadedFiles() : Files`

##### Return values

Files —

#### getUri()

AbstractRequest.php : 124

Get the URI

`public getUri() : Uri`

##### Return values

Uri —

#### globals()

Request.php : 282

Read values from the GLOBALS variables ($_POST, $_GET, $_SESSION, $_COOKIE) according to the specified keys.

`public globals(array<string|int, mixed> $keys, string $name[, mixed $default = null ][, string $cookie_or_session_name = null ]) : InputItem|Inputs`

For example, if the keys are ['POST', 'GET'], it will read from $_POST first and if not found, it will read from $_GET. If the value is still not found, it will return the default value.

##### Parameters

$keys : array<string|int, mixed>

  The names of the variables to read (uppercase), e.g., ['POST', 'GET'].

$name : string

  The name of the variable.

$default : mixed = null

  The default value if the variable is not found.

$cookie_or_session_name : string = null

  The name of the cookie or session if it's different from $name.

##### Return values

InputItem|Inputs —

#### hasHeader()

AbstractMessage.php : 115

Check if a header exists.

`public hasHeader(string $name) : bool`

##### Parameters

$name : string

  The name of the header.

##### Return values

bool —

True if the header exists, false otherwise.

#### initSession()

Request.php : 312

Initialize session.

`public initSession() : bool`

##### Return values

bool —

#### isAjax()

Request.php : 359

Check if the request is made via Ajax.

`public isAjax() : bool`

Return true if the request is an Ajax request (XMLHttpRequest).

##### Return values

bool —

#### isReferer()

Request.php : 370

Check if the referer is from the same website.

`public isReferer() : bool`

Return true if the referer is from the same website.

##### Return values

bool —

#### isSafe()

Request.php : 391

Check the token from the form and validate the referer.

`public isSafe() : bool`

Only accepts values from $_POST. This function must be called after initSession() every time. The token has a lifetime defined by TOKEN_LIMIT. Return true if the token is valid and not expired.

##### Return values

bool —

#### map()

AbstractRequest.php : 139

Merge arrays $_GET and $_POST into a single data array

`public static map(array<string|int, mixed> &$result, array<string|int, mixed> $array[, array<string|int, mixed> $exclude = [] ]) : mixed`

##### Parameters

$result : array<string|int, mixed>

  A variable to store the result for further use

$array : array<string|int, mixed>

  The array to merge, e.g., $_GET or $_POST

$exclude : array<string|int, mixed> = []

  A list of keys from the array that should not be included in the result

##### Return values

mixed —

#### post()

Request.php : 416

Read a value from the $_POST variable.

`public post(string $name[, mixed $default = null ][, string|null $cookie = null ]) : InputItem|Inputs`

If not found, return the $default value. Return an InputItem or an array of InputItem.

##### Parameters

$name : string

  The variable name.

$default : mixed = null

  The default value if the variable is not found.

$cookie : string|null = null

  null (default) to not read from cookie, string the name of the cookie to read from.

##### Return values

InputItem|Inputs —

#### removeToken()

Request.php : 428

Remove the token.

`public removeToken() : mixed`

##### Return values

mixed —

#### request()

Request.php : 447

Read a value from the $_POST, $_GET, $_COOKIE (optional) variables in order.

`public request(string $name[, mixed $default = null ][, string|null $cookie = null ]) : InputItem|Inputs`

Return the first item found, if not found, return the $default value. Return an InputItem or an array of InputItem.

##### Parameters

$name : string

  The variable name.

$default : mixed = null

  The default value if the variable is not found.

$cookie : string|null = null

  null (default) to not read from cookie, string the name of the cookie to read from.

##### Return values

InputItem|Inputs —

#### server()

Request.php : 465

Read a value from the $_SERVER variable.

`public server(string $name[, mixed $default = null ]) : mixed`

If not found, return the $default value.

##### Parameters

$name : string

  The variable name.

$default : mixed = null

  The default value if the variable is not found.

##### Return values

mixed —

#### session()

Request.php : 480

Read a value from the $_SESSION variable.

`public session(string $name[, mixed $default = null ]) : InputItem|Inputs`

If not found, return the $default value. Return an InputItem or a Collection of InputItem.

##### Parameters

$name : string

  The variable name.

$default : mixed = null

  The default value if the variable is not found.

##### Return values

InputItem|Inputs —

#### setSession()

Request.php : 493

Set the value of $_SESSION variable.

`public setSession(string $name, mixed $value) : static`

##### Parameters

$name : string

  The variable name.

$value : mixed

  The value of the variable.

##### Return values

static —

#### withAddedHeader()

AbstractMessage.php : 130

Add a new header.

`public withAddedHeader(string $name, string|array<string|int, string> $value) : static`

##### Parameters

$name : string

  The name of the header.

$value : string|array<string|int, string>

  The value(s) of the header as a string or an array of strings.

##### Tags

throws
  InvalidArgumentException

  If the header name is invalid.

##### Return values

static —

#### withAttribute()

Request.php : 507

Set the value of attributes.

`public withAttribute(string $name, mixed $value) : static`

##### Parameters

$name : string

  The name of the attribute.

$value : mixed

  The value of the attribute.

##### Return values

static —

#### withBody()

AbstractMessage.php : 151

Set the message body.

`public withBody(StreamInterface $body) : static`

##### Parameters

$body : StreamInterface

  The message body.

##### Return values

static —

#### withCookieParams()

Request.php : 521

Set the value of cookieParams.

`public withCookieParams(array<string|int, mixed> $cookies) : static`

##### Parameters

$cookies : array<string|int, mixed>

  The cookie parameters.

##### Return values

static —

#### withHeader()

AbstractMessage.php : 168

Set a header, replacing any existing values.

`public withHeader(string $name, string|array<string|int, string> $value) : static`

##### Parameters

$name : string

  The name of the header.

$value : string|array<string|int, string>

  The value(s) of the header as a string or an array of strings.

##### Tags

throws
  InvalidArgumentException

  for invalid header names or values.

##### Return values

static —

#### withHeaders()

AbstractMessage.php : 185

Set multiple headers, replacing any existing values.

`public withHeaders(array<string|int, mixed> $headers) : static`

##### Parameters

$headers : array<string|int, mixed>

  An array of headers in the format: array($key => $value, $key => $value...)

##### Tags

throws
  InvalidArgumentException

  for invalid header names or values.

##### Return values

static —

#### withMethod()

AbstractRequest.php : 161

Set the HTTP method

`public withMethod(string $method) : static`

##### Parameters

$method : string

  The HTTP method

##### Return values

static —

#### withoutAttribute()

Request.php : 577

Removes attributes.

`public withoutAttribute(string|array<string|int, mixed> $names) : static`

##### Parameters

$names : string|array<string|int, mixed>

  The names of the attributes to remove.

##### Return values

static —

#### withoutHeader()

AbstractMessage.php : 216

Remove a header.

`public withoutHeader(string $name) : static`

##### Parameters

$name : string

  The name of the header to remove.

##### Return values

static —

#### withParsedBody()

Request.php : 535

Set the value of parsedBody.

`public withParsedBody(mixed $data) : static`

##### Parameters

$data : mixed

  The parsed body data.

##### Return values

static —

#### withProtocolVersion()

AbstractMessage.php : 202

Set the protocol version of the message.

`public withProtocolVersion(string $version) : static`

##### Parameters

$version : string

  The protocol version (e.g., 1.1, 1.0).

##### Return values

static —

#### withQueryParams()

Request.php : 549

Set the value of queryParams.

`public withQueryParams(array<string|int, mixed> $query) : static`

##### Parameters

$query : array<string|int, mixed>

  The query parameters.

##### Return values

static —

#### withRequestTarget()

AbstractRequest.php : 175

Set the request target

`public withRequestTarget(mixed $requestTarget) : static`

##### Parameters

$requestTarget : mixed

  The request target

##### Return values

static —

#### withUploadedFiles()

Request.php : 563

Set the value of uploadedFiles.

`public withUploadedFiles(array<string|int, mixed> $uploadedFiles) : static`

##### Parameters

$uploadedFiles : array<string|int, mixed>

  The uploaded files.

##### Return values

static —

#### withUri()

AbstractRequest.php : 190

Set the URI

`public withUri(UriInterface $uri[, bool $preserveHost = false ]) : static`

##### Parameters

$uri : UriInterface

  The URI

$preserveHost : bool = false

  Whether to preserve the host header

##### Return values

static —

#### filterHeader()

AbstractMessage.php : 230

Check the validity of a header.

`protected filterHeader(string $name) : mixed`

##### Parameters

$name : string

  The name of the header.

##### Tags

throws
  InvalidArgumentException

  If the header is invalid.

##### Return values

mixed —

#### getRequestHeaders()

AbstractMessage.php : 242

Function to retrieve HTTP headers.

`protected getRequestHeaders() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

An array of HTTP headers.

#### createInputItem()

Request.php : 601

Reads a value from the $source.

`private createInputItem(array<string|int, mixed> $source, string $name, mixed $default, string|null $type) : InputItem|Inputs`

Returns an InputItem or a Collection of InputItem.

##### Parameters

$source : array<string|int, mixed>

  The GET or POST variables.

$name : string

  The variable name.

$default : mixed

  The default value if the variable is not found.

$type : string|null

  The type of input (e.g., GET, POST, SESSION, COOKIE) or null if not from the listed sources.

##### Return values

InputItem|Inputs —

## Search results