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.

No constants
Request body. This is only used in certain circumstances such as with XML-RPC or REST.
In the case where the request is of content-type application/json this is the decoded JSON body.
Array of headers, one line per element.
Request method
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.

getHeader($header) : mixed

Get a single header value

getHeaders() : array

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

getMethod() : string

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

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.

getRequestBody() : string

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

hasHeader($header) : bool

Check if a header was sent in the HTTP request.

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.

isDelete() : boolean

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

isGet() : boolean

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

isPost() : boolean

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

isPut() : boolean

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

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.

redirectURI() : string

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