HTTP
HTTP
Controller HTTP Request Class
The HTTP controller 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
queryParam
public string $queryParam
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
public init({Array})
The HTTP init method takes only a single optional argument which is the request array provided by PHP ($_REQUEST).
The constructor will also get all the request headers and the request content and from there will use the [[Hazaar\Application\Request]] 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 | |
$request | array | Optional reference to $_REQUEST |
$processRequestBody | bool |
isGet
public isGet({Array})
Test if the request method is GET. This is a convenience method for quickly determining the request method.
isPut
public isPut({Array})
Test if the request method is PUT. This is a convenience method for quickly determining the request method.
isPost
public isPost({Array})
Test if the request method is POST. This is a convenience method for quickly determining the request method.
isDelete
public isDelete({Array})
Test if the request method is DELETE. This is a convenience method for quickly determining the request method.
getHeaders
public getHeaders({Array})
Get all the HTTP request headers sent by the client browser.
hasHeader
public hasHeader({Array})
Check if a header was sent in the HTTP request.
Parameters
Parameter | Type | Description |
---|---|---|
$header | string |
getHeader
public getHeader({Array})
Get a single header value
Parameters
Parameter | Type | Description |
---|---|---|
$header | string |
getContentType
Return the current request content type.
public getContentType({Array})
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.
isXmlHttpRequest
public isXmlHttpRequest({Array})
Test 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({Array})
Returns the URI of the page this request was redirected from.
getRequestBody
public getRequestBody({Array})
Returns the body of the request. This will normally be null unless the request is a POST or PUT.
getJSONBody
public getJSONBody({Array})
Returns 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
public getRemoteAddr({Array})
isMobileDevice
Detect if a request originated on a mobile device.
public isMobileDevice({Array})
This 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({Array})
Generated by Hazaar API Doc Generator