Request
Request
Application HTTP Request Class.
The HTTP request class is a representational object for an HTTP request. The Application object will create a HTTP request object upon each execution. This object contains all details of the current request including request data, headers and any request body content.
If you want to generate your own HTTP request object to pass to another method or function that requires one, see Hazaar\HTTP\Request.
Properties
pathParam
public string $pathParam = 'hzpath'queryParam
public string $queryParam = 'hzqs'body
public string $bodydispatched
protected bool $dispatchedparams
protected array $paramspublic $method
Request method.
protected string $method = 'GET'path
The requested path.
private string $pathheaders
Array of headers, one line per element.
private array $headersMethods
__construct
public __construct(?array $server): voidThe HTTP request object constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$server | array | Optional reference to $_SERVER |
__get
Magic method to get the value of a property.
public __get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the name of the property to get |
__unset
Unsets a value from the request object.
public __unset(string $key): voidThis method removes a value from the request object using the specified key.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the value to unset |
init
The Application HTTP request object initialisation method.
public init(?array $server): stringThis method is called by the constructor to initialise the request object. It will parse the request URI and any request parameters and set them as properties of the object.
The constructor will also get all the request headers and the request content and
from there will use the [Hazaar\Application\Request](/api/class/Hazaar/Application/Request.md) parent class to determine the
name of the Controller and Action that is being requested via it's evaluate() method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$server | array | Optional reference to $_SERVER |
isGet
public isGet(): boolTest if the request method is GET. This is a convenience method for quickly determining the request method.
isPut
public isPut(): boolTest if the request method is PUT. This is a convenience method for quickly determining the request method.
isPost
public isPost(): boolTest if the request method is POST. This is a convenience method for quickly determining the request method.
isDelete
public isDelete(): boolTest if the request method is DELETE. This is a convenience method for quickly determining the request method.
getHeaders
public getHeaders(): voidGet all the HTTP request headers sent by the client browser.
hasHeader
public hasHeader(string $header): boolCheck if a header was sent in the HTTP request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string |
getHeader
public getHeader(string $header): stringGet a single header value
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string |
setHeader
Sets a header value for the request.
public setHeader(string $header, string $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$header | string | the name of the header to set |
$value | string | the value to assign to the header |
getContentType
Return the current request content type.
public getContentType(): stringThis is a helpful method for doing a few things in one go as it will only return a content type if the request is a POST method. Otherwise it will safely return a FALSE value.
isXmlHttpRequest
public isXmlHttpRequest(): boolTest if the request originated from an XMLHttpRequest object. This object is used when sending an AJAX request from withing a JavaScript function. All of the major JavaScript libraries (jQuery, extJS, etc) will set the X-Requested-With header to indicate that the request is an AJAX request.
Using this in your application will allow you to determine how to respond to the request. For example, you might want to forgo rendering a view and instead return a JSON response.
redirectURI
public redirectURI(): ?stringReturns the URI of the page this request was redirected from.
getRequestBody
public getRequestBody(): stringReturns the body of the request. This will normally be null unless the request is a POST or PUT.
getJSONBody
public getJSONBody(?bool $assoc, int $depth = 512): mixedReturns the JSON decoded body of the request. This will normally be null unless the request is a POST or PUT and content-type is application/json.
Parameters
| Parameter | Type | Description |
|---|---|---|
$assoc | bool | |
$depth | int |
getRemoteAddr
Get the remote IP address of the requesting host.
public getRemoteAddr(): ?stringThis will try to determine the correct IP to return. By default it will return the $_SERVER['REMOTE_ADDR'] value, but if the connection is via a reverse proxy (such as Haproxy) then it will possibly have the standard X-Forwarded-For header, so if that header exists then that value will be returned.
isMobileDevice
Detect if a request originated on a mobile device.
public isMobileDevice(): boolThis method will return true to indicate that the requesting device is a mobile browser. It uses the freely available script from detectmobilebrowsers.com
referer
Get the referer URL from the HTTP request headers.
public referer(): ?stringgetPath
Return the request path.
public getPath(bool $stripFilename): stringParameters
| Parameter | Type | Description |
|---|---|---|
$stripFilename | bool | If true, this will cause the function to return anything before the last '/' (including the '/') which is the full directory path name. (Similar to dirname()). |
setPath
Sets the path of the request.
public setPath(string $path): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the path of the request |
get
Retrieve a request value.
public get(string $key, mixed $default): mixedThese values can be sent in a number of ways.
- In a query string. eg: http://youhost.com/controller?key=value
- As form POST data.
- As JSON encoded request body.
Only JSON encoded request bodies support data typing. All other request values will be strings.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The data key to retrieve |
$default | mixed | if the value is not set, use this default value |
getInt
Retrieve an integer value from the request.
public getInt(string $key, ?int $default): ?intThe most common requests will not provide data typing and data value will always be a string. This method will automatically return the requested value as an integer unless it is NULL or not set. In which case either NULL or the default value will be returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the request value to return |
$default | int | a default value to use if the value is NULL or not set |
getFloat
Retrieve an float value from the request.
public getFloat(string $key, ?float $default): floatThe most common requests will not provide data typing and data value will always be a string. This method will automatically return the requested value as an float unless it is NULL or not set. In which case either NULL or the default value will be returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the request value to return |
$default | float | a default value to use if the value is NULL or not set |
getBool
Retrieve an boolean value from the request.
public getBool(string $key, NULL $default): boolThe most common requests will not provide data typing and data value will always be a string. This method will automatically return the requested value as an boolean unless it is NULL or not set. In which case either NULL or the default value will be returned.
This internally uses the \Hazaar\Util\Boolean::from() function so the usual bool strings are supported (t, f, true, false, 0, 1, on, off, etc).
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the request value to return |
$default | NULL | a default value to use if the value is NULL or not set |
has
Check to see if a request value has been set.
public has(string $keys, bool $checkAny): boolParameters
| Parameter | Type | Description |
|---|---|---|
$keys | string | the key of the request value to check for |
$checkAny | bool | The check type when $key is an array. TRUE means that ANY key must exist. FALSE means ALL keys must exist. |
set
Set a request value.
public set(string $key, mixed $value): voidThis would not normally be used and has no internal implications on how the application will function as this data is not processed in any way. However setting request data may be useful in your application when reusing/repurposing controller actions so that they may be called from somewhere else in your application.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key value to set |
$value | mixed | the new value |
remove
Removes a parameter from the request.
public remove(string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the parameter to remove |
getParams
Return an array of request parameters as key/value pairs.
public getParams(?array $filterIn, ?array $filterOut): voidParameters
| Parameter | Type | Description |
|---|---|---|
$filterIn | array | only include parameters with keys specified in this filter |
$filterOut | array | exclude parameters with keys specified in this filter |
hasParams
Check if the request has any parameters.
public hasParams(): boolsetParams
Sets the parameters of the request.
public setParams(array $array): voidParameters
| Parameter | Type | Description |
|---|---|---|
$array | array | The array of parameters to set |
count
Returns the number of parameters in the request.
public count(): intgetMethod
public getMethod(): stringReturns the method used to initiate this request on the server. .
getRequestHeaders
Get the current request headers.
public getRequestHeaders(): voidThis function will return the current request headers as an associative array.
Generated by Hazaar API Doc Generator on Wed, 07 Jan 2026 11:29:59 +0000