PHP Class Respect\Rest\Request

Show file Open project: respect/rest Class Usage Examples

Public Properties

Property Type Description
$method The HTTP method (commonly GET, POST, PUT, DELETE, HEAD)
$params A numeric array containing valid URL parameters. For a route path like /users/*, a Request for /users/alganet should have an array equivalent to ['alganet']
$route A route matched for this request
$uri The called URI

Public Methods

Method Description
__construct ( string $method = null, string $uri = null )
__toString ( ) Converting this request to string dispatch
forward ( Respect\Rest\Routes\AbstractRoute $route ) : Response Forwards a route
response ( ) : string Generates and returns the response from the current route
routineCall ( string $type, string $method, Respect\Rest\Routines\Routinable $routine, array &$params ) : mixed Calls a routine on the current route and returns its result

Protected Methods

Method Description
catchExceptions ( Exception $e ) : mixed Does a catch-like operation on an exception based on previously declared instances from Router::exceptionRoute
extractRouteParam ( ReflectionFunctionAbstract $callback, ReflectionParameter $routeParam, array &$params ) : mixed Extracts a parameter value from the current route
forwardErrors ( mixed $errorHandler ) : mixed Restores the previous error handler if present then check error routes for logged errors, forwarding them or returning null silently
prepareForErrorForwards ( ) : mixed Declares an error handler for a single Router::errorRoute instance on the fly before dispatching the request, so the application can capture the errors. These are cleaned after dispatching by forwardErrors()
processPosRoutines ( $response ) : mixed Iterates over routines to find instances of Respect\Rest\Routines\ProxyableThrough and call them, forwarding if necessary
processPreRoutines ( ) : mixed Iterates over routines to find instances of Respect\Rest\Routines\ProxyableBy and call them, forwarding if necessary

Method Details

__construct() public method

public __construct ( string $method = null, string $uri = null )
$method string The HTTP method
$uri string The called URI

__toString() public method

Converting this request to string dispatch
public __toString ( )

catchExceptions() protected method

Does a catch-like operation on an exception based on previously declared instances from Router::exceptionRoute
protected catchExceptions ( Exception $e ) : mixed
$e Exception Any exception
return mixed A route forwarding or a silent null

extractRouteParam() protected method

Extracts a parameter value from the current route
protected extractRouteParam ( ReflectionFunctionAbstract $callback, ReflectionParameter $routeParam, array &$params ) : mixed
$callback ReflectionFunctionAbstract Any function reflection
$routeParam ReflectionParameter Any parameter reflection
$params array Request URI params
return mixed a value from the reflected param

forward() public method

Forwards a route
public forward ( Respect\Rest\Routes\AbstractRoute $route ) : Response
$route Respect\Rest\Routes\AbstractRoute Any route
return Response from the forwarded route

forwardErrors() protected method

Restores the previous error handler if present then check error routes for logged errors, forwarding them or returning null silently
protected forwardErrors ( mixed $errorHandler ) : mixed
$errorHandler mixed Some error handler (internal or external to Respect)
return mixed A route forwarding or a silent null

prepareForErrorForwards() protected method

Declares an error handler for a single Router::errorRoute instance on the fly before dispatching the request, so the application can capture the errors. These are cleaned after dispatching by forwardErrors()
See also: Respect\Rest\Request::forwardErrors
See also: http://php.net/set_error_handler
protected prepareForErrorForwards ( ) : mixed
return mixed The previous error handler

processPosRoutines() protected method

Iterates over routines to find instances of Respect\Rest\Routines\ProxyableThrough and call them, forwarding if necessary
See also: Respect\Rest\Routines\ProxyableThrough
See also: Respect\Rest\Request::routineCall
protected processPosRoutines ( $response ) : mixed
return mixed A route forwarding or false

processPreRoutines() protected method

Iterates over routines to find instances of Respect\Rest\Routines\ProxyableBy and call them, forwarding if necessary
See also: Respect\Rest\Routines\ProxyableBy
See also: Respect\Rest\Request::routineCall
protected processPreRoutines ( ) : mixed
return mixed A route forwarding or false

response() public method

Generates and returns the response from the current route
public response ( ) : string
return string A response!

routineCall() public method

Calls a routine on the current route and returns its result
public routineCall ( string $type, string $method, Respect\Rest\Routines\Routinable $routine, array &$params ) : mixed
$type string The name of the routine (accept, when, etc)
$method string The method name (GET, HEAD, POST, etc)
$routine Respect\Rest\Routines\Routinable Some routine instance
$params array Params from the routine
return mixed Whatever the routine returns

Property Details

$method public property

The HTTP method (commonly GET, POST, PUT, DELETE, HEAD)
public $method

$params public property

A numeric array containing valid URL parameters. For a route path like /users/*, a Request for /users/alganet should have an array equivalent to ['alganet']
public $params

$route public property

A route matched for this request
public $route

$uri public property

The called URI
public $uri