ARouter  0.1.0
Annotation based router for your projects
RouteHandler Class Reference

Public Member Functions

 __construct ($controller, $method, $keyedArgs=[])
 
 convertKeyedArgs (array $keyedArgs)
 
 execute ()
 
 getController ()
 
 getMethod ()
 
 getKeyedArgs ()
 

Detailed Description

Handler for producing HTTP response from controller action methods.

Route handler calls provided controller method with provided arguments. Router is responsible for creating correct RouteHandler object for incoming request.

Action method arguments are passed as array in form of ['argument name' => 'argument value'].

E.g. If you have MyController class with method function contactPage($name, $message) the correct handler creation code will be

new RouteHandler(new MyController(), 'contactPage',
['name' => 'Foo', 'message' => 'Bar'])'

If you provide less arguments than needed the exception will be thrown on handler creation.

See also

Constructor & Destructor Documentation

◆ __construct()

__construct (   $controller,
  $method,
  $keyedArgs = [] 
)

RouteHandler constructor.

Parameters
object$controllerController object.
string$methodName of controller method.
array$keyedArgsController method arguments in form of ['argument name' => 'argument value'].

Member Function Documentation

◆ convertKeyedArgs()

convertKeyedArgs ( array  $keyedArgs)

Convert controller method keyed arguments to form compatible with call_user_func_array

Parameters
array$keyedArgsController method keyed arguments.
Returns
array Converted arguments.
Exceptions

◆ execute()

execute ( )

Execute route handler and return result.

Exceptions

◆ getController()

getController ( )

Get controller object.

Returns
object

◆ getKeyedArgs()

getKeyedArgs ( )

Get method arguments are passed as array in form of ['argument name' => 'argument value'].

Returns
array Keyed method arguments.

◆ getMethod()

getMethod ( )

Get controller method name.

Returns
string Controller method name.

The documentation for this class was generated from the following file: