\Hazaar\Application\Request
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]].

Tags

Since

1.0.0

Summary
Methods Properties Constants
No constants
Properties
$body
$body
Request body. This is only used in certain circumstances such as with XML-RPC or REST.
$bodyJSON
$bodyJSON
In the case where the request is of content-type application/json this is the decoded JSON body.
$headers
$headers
Array of headers, one line per element.
$method
$method
Request method
Static
$pathParam
$pathParam
Static
$queryParam
$queryParam
Methods
getContentType()
getContentType() : mixed
Return the current request content type.

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.

Returns

mixed

The content type of the POST request. False if the request is not a POST request.

getHeader()
getHeader($header) : mixed

Get a single header value

Parameters

$header

No description

Returns

mixed

Returns the header value if it exists. Null otherwise.

getHeaders()
getHeaders() : array

Get all the HTTP request headers sent by the client browser.

Tags

Since

2.0.0

Returns

array

An array of headers with the key as the header name and the value as the header value.

getMethod()
getMethod() : string

Returns the method used to initiate this request on the server. .

Tags

Since

1.0.0

Returns

string

The request method. Usually one of GET, POST, PUT or DELETE.

getRemoteAddr()
getRemoteAddr() : mixed
Get the remote IP address of the requesting host

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.

Returns

mixed
getRequestBody()
getRequestBody() : string

Returns the body of the request. This will normally be null unless the request is a POST or PUT.

Returns

string

The request body.

hasHeader()
hasHeader($header) : bool

Check if a header was sent in the HTTP request.

Parameters

$header

No description

Returns

bool

TRUE if the header was sent.

init()
init($request = null)

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.

Tags

Since

1.0.0

Parameters

$request\Array

Optional reference to $_REQUEST

isDelete()
isDelete() : boolean

Test if the request method is DELETE. This is a convenience method for quickly determining the request method.

Tags

Since

1.0.0

Returns

boolean

True if method is DELETE. False otherwise.

isGet()
isGet() : boolean

Test if the request method is GET. This is a convenience method for quickly determining the request method.

Tags

Since

1.0.0

Returns

boolean

True if method is GET. False otherwise.

isPost()
isPost() : boolean

Test if the request method is POST. This is a convenience method for quickly determining the request method.

Tags

Since

1.0.0

Returns

boolean

True if method is POST. False otherwise.

isPut()
isPut() : boolean

Test if the request method is PUT. This is a convenience method for quickly determining the request method.

Tags

Since

1.0.0

Returns

boolean

True if method is PUT. False otherwise.

isXmlHttpRequest()
isXmlHttpRequest() : boolean

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.

Tags

Since

1.0.0

Returns

boolean

True to indicate the X-Requested-With is set. False otherwise.

redirectURI()
redirectURI() : string

Returns the URI of the page this request was redirected from.

Tags

Since

1.0.0

Returns

string

Original request URI