HTTP
HTTP
- Full name:
\Hazaar\Application\Request\HTTP
- Parent class:
\Hazaar\Application\Request
Properties
pathParam
public static string $pathParam
- This property is static.
queryParam
public static string $queryParam
- This property is static.
body
Request body. This is only used in certain circumstances such as with XML-RPC or REST.
public string $body
headers
Array of headers, one line per element.
private array $headers
Methods
init
Returns the request as a string.
public init(?array $server, array $request = null, bool $processRequestBody = false): string
Parameters:
Parameter | Type | Description |
---|---|---|
$server | ?array | |
$request | array | Optional reference to $_REQUEST |
$processRequestBody | bool |
isGet
public isGet(): bool
Return Value:
True if method is GET. False otherwise.
isPut
public isPut(): bool
Return Value:
True if method is PUT. False otherwise.
isPost
public isPost(): bool
Return Value:
True if method is POST. False otherwise.
isDelete
public isDelete(): bool
Return Value:
True if method is DELETE. False otherwise.
getHeaders
public getHeaders(): string[]
Return Value:
an array of headers with the key as the header name and the value as the header value
hasHeader
public hasHeader(mixed $header): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$header | mixed | string The header to check |
Return Value:
TRUE if the header was sent
getHeader
public getHeader(mixed $header): string
Parameters:
Parameter | Type | Description |
---|---|---|
$header | mixed | string The header value to get |
Return Value:
Returns the header value if it exists. Null otherwise.
getContentType
Return the current request content type.
public getContentType(): false|string
This 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.
Return Value:
The content type of the POST request. False if the request is not a POST request.
isXmlHttpRequest
public isXmlHttpRequest(): bool
Return Value:
True to indicate the X-Requested-With is set. False otherwise.
redirectURI
public redirectURI(): string
Return Value:
Original request URI
getRequestBody
public getRequestBody(): string
Return Value:
the request body
getJSONBody
public getJSONBody(?bool $assoc = null, int $depth = 512): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$assoc | ?bool | |
$depth | int |
getRemoteAddr
Get the remote IP address of the requesting host.
public static getRemoteAddr(): ?string
This 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.
- This method is static.
isMobileDevice
Detect if a request originated on a mobile device.
public isMobileDevice(): bool
This method will return true to indicate that the requesting device is a mobile browser. It uses the freely available script from detectmobilebrowsers.com
Return Value:
true to indicate requesting device is a mobile browser, false otherwise
referer
Get the referer URL from the HTTP request headers.
public referer(): null|string
Return Value:
the referer URL if available, null otherwise
Inherited methods
__construct
public __construct(mixed $args): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$args | mixed |
__get
Magic method to get the value of a property.
public __get(string $key): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key | string | the name of the property to get |
Return Value:
the value of the property
__unset
Unsets a value from the request object.
public __unset(string $key): void
This 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 |
getPath
Return the request path.
public getPath(bool $stripFilename = false): string
Parameters:
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()). |
Return Value:
The path suffix of the request URI
setPath
Sets the path of the request.
public setPath(string $path): void
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string | the path of the request |
get
Retrieve a request value.
public get(string $key, mixed $default = null): mixed
These 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 |
Return Value:
most of the time this will return a string, unless data-typing is available when using JSON requests
getInt
Retrieve an integer value from the request.
public getInt(string $key, int $default = null): ?int
The 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 = null): float
The 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, bool $default = null): bool
The 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 boolify() 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 | bool | 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[]|string $keys, bool $check_any = false): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$keys | string[]|string | the key of the request value to check for |
$check_any | bool | The check type when $key is an array. TRUE means that ANY key must exist. FALSE means ALL keys must exist. |
Return Value:
true if the value is set, False otherwise
set
Set a request value.
public set(string $key, mixed $value): void
This 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): void
Parameters:
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(string[] $filter_in = null, string[] $filter_out = null): array
Parameters:
Parameter | Type | Description |
---|---|---|
$filter_in | string[] | only include parameters with keys specified in this filter |
$filter_out | string[] | exclude parameters with keys specified in this filter |
Return Value:
the request parameters
hasParams
Check if the request has any parameters.
public hasParams(): bool
Return Value:
returns true if the request has parameters, false otherwise
setParams
Sets the parameters of the request.
public setParams(array $array): void
Parameters:
Parameter | Type | Description |
---|---|---|
$array | array | The array of parameters to set |
count
Returns the number of parameters in the request.
public count(): int
Return Value:
the number of parameters in the request
getMethod
public getMethod(): string
Return Value:
The request method. Usually one of GET, POST, PUT or DELETE.
init
Returns the request as a string.
protected init(array $args): string
Parameters:
Parameter | Type | Description |
---|---|---|
$args | array |
Automatically generated on 2024-11-14