\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
has
set
No constants
Properties
$accept_methods
$accept_methods
$body
$body
Request body. This is only used in certain circumstances such as with XML-RPC.
$headers
$headers
Array of headers, one line per element.
$method
$method
Request method
Inherited
$dispatched
$dispatched
Inherited
$exception
$exception
Inherited
$params
$params
Inherited
$response_type
$response_type
Methods
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.

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

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

$requestArray

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

Inherited
getRawPath()
getRawPath() : string

Return the complete raw request URI relative to the application path. That is the full path including the controller and action elements. Take the path /myapp/public/index/test/foo/bar for example. In this case this method would return ‘/index/test/foo/bar’.

Tags

Since

1.0.0

Returns

string

The raw request URI relative to the application path.

Inherited
getResponseType()
getResponseType() : string
Returns the requested response type.

The requested response type can be set in the request itself. If it is not set, then the default will be ‘html’ or the X-Requested-With header will be checked to determine the response type.

This method is used internally to determine the response type to send when one has not been explicitly used. Normally the response type is determined by the Controller\Response object type returned by a controller action.

Returns

string
Inherited
has()
has($keys)

Parameters

$keys

No description

Inherited
hasException()
hasException()
Inherited
hasParams()
hasParams()
Inherited
isDELETE()
isDELETE()
Inherited
isDispatched()
isDispatched()
Inherited
isGET()
isGET()
Inherited
isMobileDevice()
isMobileDevice() : boolean
Detect if a request originated on a mobile device

This method will return true to indicate that the requesting device is a mobile browser. It uses the freely available script from detectmobilebrowsers.com

Returns

boolean

True to indicate requesting device is a mobile browser, false otherwise.

Inherited
isPOST()
isPOST()
Inherited
isPUT()
isPUT()
Inherited
method()
method()
Inherited
processRoute()
processRoute()
Inherited
referer()
referer()
Inherited
remove()
remove($key)

Parameters

$key

No description

Inherited
resetAction()
resetAction()
Inherited
set()
set($key, $value)

Parameters

$key

No description

$value

No description

Inherited
setActionName()
setActionName($name)

Parameters

$name

No description

Inherited
setControllerName()
setControllerName($name)

Parameters

$name

No description

Inherited
setDispatched()
setDispatched($flag = true)

Parameters

$flag

No description

Inherited
setException()
setException($e)

Parameters

$e\Hazaar\Application\Request\Exception

No description

Inherited
setParams()
setParams($array)

Parameters

$arrayarray

No description

Inherited
setResponseType()
setResponseType($type)

Parameters

$type

No description