class Request

Executes requets.

Constants

REMOTE_ADDRESS_FALLBACK

Remote address fallback.

Properties

protected string $scriptName Script name.
protected Parameters $query Get data.
protected Parameters $post Post data.
protected Cookies $cookies Cookie data.
protected Files $files File data.
protected Server $server Server info.
protected Headers $headers Request headers.
protected string $rawBody Raw request body.
protected Body $parsedBody Parsed request body.
protected string $contentType Content type.
protected array $trustedProxies Array of trusted proxy IP addresses.
protected string $ip Ip address of the client that made the request.
protected string $basePath Base path of the request.
protected string $baseURL Base URL of the request.
protected string $path Holds the request path.
protected array $language Request language.
protected string $languagePrefix Request language prefix.
protected string $method Which request method was used?
protected string $realMethod The actual request method that was used.
protected bool $isSecure Was this request made using HTTPS?
protected Route $route The route that matched the request.
protected array $attributes Request attribuntes.

Methods

__construct(array $request = [], Signer|null $signer = null)

Constructor.

string
stripLocaleSegment(array $languages, string $path)

Strips the locale segment from the path.

string
determinePath(array $languages)

Determines the request path.

string
determineMethod()

Determines the request method.

string
getContentType()

Returns the content type of the request body.

string
getScriptName()

Returns the base name of the script that handled the request.

setRoute(Route $route)

Set the route that matched the request.

Route|null
getRoute()

Returns the route that matched the request.

setAttribute(string $name, mixed $value)

Sets a request attribute.

mixed
getAttribute(string $name, mixed $default = null)

Gets a request attribute.

string
getRawBody()

Returns the raw request body.

resource
getRawBodyAsStream()

Returns the raw request body as a stream.

getQuery()

Returns the query string.

getPost()

Returns the post data.

getCookies()

Returns the cookies.

getFiles()

Returns the files.

getServer()

Returns the files.

getHeaders()

Returns the files.

getBody()

Returns the parsed request body.

bool
hasFormData()

Returns TRUE if the request has form data and FALSE if not.

getData()

Returns the data of the current request method.

setTrustedProxies(array $trustedProxies)

Set the trusted proxies.

bool
isTrustedProxy(string $ip)

Is this IP a trusted proxy?

string
getIp()

Returns the ip of the client that made the request.

bool
isAjax()

Returns TRUE if the request was made using Ajax and FALSE if not.

bool
isSecure()

Returns TRUE if the request was made using HTTPS and FALSE if not.

bool
isSafe()

Returns TRUE if the request method is considered safe and FALSE if not.

bool
isIdempotent()

Returns TRUE if the request method is considered idempotent and FALSE if not.

bool
isCacheable()

Returns TRUE if the request method is considered cacheable and FALSE if not.

bool
isCGI()

Is PHP running as a CGI program?

string
getBasePath()

Returns the base path of the request.

string
getBaseURL()

Returns the base url of the request.

string
getPath()

Returns the request path.

bool
isClean()

Returns TRUE if the resource was requested with a "clean" URL and FALSE if not.

array|null
getLanguage()

Returns the request language.

string|null
getLanguagePrefix()

Returns the request language prefix.

string
getMethod()

Returns the request method that was used.

string
getRealMethod()

Returns the real request method that was used.

bool
isFaked()

Returns TRUE if the request method has been faked and FALSE if not.

string|null
getUsername()

Returns the basic HTTP authentication username or null.

string|null
getPassword()

Returns the basic HTTP authentication password or null.

mixed
getReferrer(mixed $default = null)

Returns the referrer.

Details

at line 216
__construct(array $request = [], Signer|null $signer = null)

Constructor.

Parameters

array $request Request data and options
Signer|null $signer Signer instance used to validate signed cookies

at line 248
protected string stripLocaleSegment(array $languages, string $path)

Strips the locale segment from the path.

Parameters

array $languages Locale segments
string $path Path

Return Value

string

at line 273
protected string determinePath(array $languages)

Determines the request path.

Parameters

array $languages Locale segments

Return Value

string

at line 315
protected string determineMethod()

Determines the request method.

Return Value

string

at line 333
string getContentType()

Returns the content type of the request body.

An empty string will be returned if the header is missing.

Return Value

string

at line 348
string getScriptName()

Returns the base name of the script that handled the request.

Return Value

string

at line 358
setRoute(Route $route)

Set the route that matched the request.

Parameters

Route $route Route

at line 368
Route|null getRoute()

Returns the route that matched the request.

Return Value

Route|null

at line 379
setAttribute(string $name, mixed $value)

Sets a request attribute.

Parameters

string $name Attribute name
mixed $value Attribute value

at line 391
mixed getAttribute(string $name, mixed $default = null)

Gets a request attribute.

Parameters

string $name Attribute name
mixed $default Default value

Return Value

mixed

at line 401
string getRawBody()

Returns the raw request body.

Return Value

string

at line 416
resource getRawBodyAsStream()

Returns the raw request body as a stream.

Return Value

resource

at line 426
Parameters getQuery()

Returns the query string.

Return Value

Parameters

at line 436
Parameters getPost()

Returns the post data.

Return Value

Parameters

at line 446
Cookies getCookies()

Returns the cookies.

Return Value

Cookies

at line 456
Files getFiles()

Returns the files.

Return Value

Files

at line 466
Server getServer()

Returns the files.

Return Value

Server

at line 476
Headers getHeaders()

Returns the files.

Return Value

Headers

at line 486
Body getBody()

Returns the parsed request body.

Return Value

Body

at line 501
protected bool hasFormData()

Returns TRUE if the request has form data and FALSE if not.

Return Value

bool

at line 518
Parameters getData()

Returns the data of the current request method.

Return Value

Parameters

at line 537
setTrustedProxies(array $trustedProxies)

Set the trusted proxies.

Parameters

array $trustedProxies Array of trusted proxy IP addresses

at line 548
protected bool isTrustedProxy(string $ip)

Is this IP a trusted proxy?

Parameters

string $ip IP address

Return Value

bool

at line 566
string getIp()

Returns the ip of the client that made the request.

Return Value

string

at line 605
bool isAjax()

Returns TRUE if the request was made using Ajax and FALSE if not.

Return Value

bool

at line 615
bool isSecure()

Returns TRUE if the request was made using HTTPS and FALSE if not.

Return Value

bool

at line 635
bool isSafe()

Returns TRUE if the request method is considered safe and FALSE if not.

Return Value

bool

at line 645
bool isIdempotent()

Returns TRUE if the request method is considered idempotent and FALSE if not.

Return Value

bool

at line 655
bool isCacheable()

Returns TRUE if the request method is considered cacheable and FALSE if not.

Return Value

bool

at line 665
bool isCGI()

Is PHP running as a CGI program?

Return Value

bool

at line 675
string getBasePath()

Returns the base path of the request.

Return Value

string

at line 692
string getBaseURL()

Returns the base url of the request.

Return Value

string

at line 727
string getPath()

Returns the request path.

Return Value

string

at line 737
bool isClean()

Returns TRUE if the resource was requested with a "clean" URL and FALSE if not.

Return Value

bool

at line 747
array|null getLanguage()

Returns the request language.

Return Value

array|null

at line 757
string|null getLanguagePrefix()

Returns the request language prefix.

Return Value

string|null

at line 767
string getMethod()

Returns the request method that was used.

Return Value

string

at line 777
string getRealMethod()

Returns the real request method that was used.

Return Value

string

at line 787
bool isFaked()

Returns TRUE if the request method has been faked and FALSE if not.

Return Value

bool

at line 797
string|null getUsername()

Returns the basic HTTP authentication username or null.

Return Value

string|null

at line 807
string|null getPassword()

Returns the basic HTTP authentication password or null.

Return Value

string|null

at line 818
mixed getReferrer(mixed $default = null)

Returns the referrer.

Parameters

mixed $default Value to return if no referrer is set

Return Value

mixed