Documentation

Request
in package
Uses TEventDispatcher

Request Class

This class represents a web request and provides access to request parameters such as GET, POST, etc.

Table of Contents

Constants

PAYLOAD_TYPE_JSON  = 'json'
PAYLOAD_TYPE_XML  = 'xml'

Properties

$address  : string
$cookie  : RequestCollection
$files  : RequestFileCollection
$get  : RequestCollection
$headers  : RequestCollection
$host  : string
$insecure  : bool
$instance  : Request|null
Singleton instance.
$post  : RequestCollection
$remoteip  : string
$server  : RequestCollection
$session  : RequestCollection
$type  : string
$uri  : string
$utm  : RequestCollection
$_encodedAsJson  : bool

Methods

__get()  : mixed
Magic getter method to access request properties.
Create()  : Request
Static constructor to create a new instance of Request.
DispatchEvent()  : object|null
Dispatches an event.
GetPayloadCopy()  : PayloadCopy
Returns a copy of the request payload as a PayloadCopy object.
GetUniqueRequestId()  : string
Generates a unique request ID based on request data.
HandleEvent()  : self
Adds an event handler.
ModifyHeaders()  : mixed
RemoveHandler()  : self
Removes an event handler.
Uri()  : string
Returns the URI with added or removed parameters.
__construct()  : mixed
Constructor.
_detectJsonEncodedData()  : void
Detects if the request payload is JSON encoded.

Constants

PAYLOAD_TYPE_JSON

public string PAYLOAD_TYPE_JSON = 'json'

Type of payload: JSON

PAYLOAD_TYPE_XML

public string PAYLOAD_TYPE_XML = 'xml'

Type of payload: XML

Properties

$address read-only

public string $address

The full address of the request.

$host read-only

public string $host

The host of the request.

$insecure read-only

public bool $insecure

Whether the request is insecure (not using HTTPS).

$instance

Singleton instance.

public static Request|null $instance = null

$remoteip read-only

public string $remoteip

The remote IP address.

$type read-only

public string $type

The type of request (e.g., GET, POST).

$uri read-only

public string $uri

The URI of the request.

$_encodedAsJson

private bool $_encodedAsJson = false

Methods

__get()

Magic getter method to access request properties.

public __get(string $prop) : mixed
Parameters
$prop : string

The property name.

Return values
mixed

The value of the property.

Create()

Static constructor to create a new instance of Request.

public static Create() : Request
Return values
Request

The Request instance.

DispatchEvent()

Dispatches an event.

public DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
$event : string|Event

The event object or its name.

$args : mixed = null

Additional arguments to pass to the event handlers.

$async : bool = false

Whether to dispatch the event asynchronously.

Return values
object|null

The event object with updated arguments, or null if the event does not exist.

GetPayloadCopy()

Returns a copy of the request payload as a PayloadCopy object.

public GetPayloadCopy([string $type = Request::PAYLOAD_TYPE_JSON ]) : PayloadCopy
Parameters
$type : string = Request::PAYLOAD_TYPE_JSON

The type of result (json, xml).

Return values
PayloadCopy

The payload copy.

GetUniqueRequestId()

Generates a unique request ID based on request data.

public GetUniqueRequestId() : string
Return values
string

The unique request ID.

HandleEvent()

Adds an event handler.

public HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
$ename : array<string|int, mixed>|string

The event name or an array of event names.

$listener : mixed

The event handler.

Return values
self

ModifyHeaders()

public ModifyHeaders([array<string|int, mixed> $headers = [] ]) : mixed
Parameters
$headers : array<string|int, mixed> = []

RemoveHandler()

Removes an event handler.

public RemoveHandler(string $ename, mixed $listener) : self
Parameters
$ename : string

The event name.

$listener : mixed

The event handler to remove.

Return values
self

Uri()

Returns the URI with added or removed parameters.

public Uri([array<string|int, mixed> $add = array() ][, array<string|int, mixed> $remove = array() ]) : string
Parameters
$add : array<string|int, mixed> = array()

Parameters to add.

$remove : array<string|int, mixed> = array()

Parameters to remove.

Return values
string

The modified URI.

__construct()

Constructor.

private __construct() : mixed

_detectJsonEncodedData()

Detects if the request payload is JSON encoded.

private _detectJsonEncodedData() : void

        
On this page

Search results