Represents an controller that maps an "action" parameter from the Trace to the corresponding method of the object, and invokes it to handle the Trace.
A method name consists of an "action_" prefix and the value of "action" parameter taken from the Trace.
If method is not defined, controller invokes ActionBasedController::handleUnknownAction() which is by default throws TraceException telling that trace is wrong. This method can be reimplemented in descendants and thus gracefully handle failed Trace handling process.
Each action method encapsulates business logic and should produce a result - an object that implements IActionResult. The controller provides some useful helper methods for doing this:
To overload a basic logic of executing a method that corresponds an action, just overload ActionBasedController::processAction() which actually invokes the found method.
Definition at line 41 of file ActionBasedController.class.php.

Public Attributes | |
| const | PARAMETER_ACTION = 'action' |
Public Member Functions | |
| getModel () | |
| Gets the current Model to be passed to presentation layer. | |
| getTrace () | |
| Gets the current trace. | |
| handle (Trace $trace) | |
| Runs the controller object to handle the incoming context. | |
Protected Member Functions | |
| filterArgumentValue (ReflectionParameter $argument) | |
| Gets the actual parameter value to be used when invoking action method. | |
| getActualParameterValue (ReflectionParameter $argument, $value) | |
| Casts the obtained value to the type expected in action method signature. | |
| getArrayValue ($action, $name, $value) | |
| Casts the parameter value which is expected to be an array according to action method signature. | |
| getClassValue ($action, $name, ReflectionClass $class, $value) | |
| Casts the parameter value which is expected to be an instance of a class according to action method signature. | |
| getMethodName ($action) | |
| Gets the name of action method. | |
| handleUnknownAction ($action) | |
| Represents an action method invoked in case when no other action method can be invoked to handle the Trace. | |
| makeActionResult ($actionResult) | |
| Cast the result of action method (of any type) to IActionResult. | |
| processAction ($action, ReflectionMethod $method) | |
| Look ups for the action method that corresponds the requested action, collects parameter values, invokes the method and wraps its result, if needed. | |
| processResult (IActionResult $actionResult) | |
| Runs the proccess of handing the action method result. | |
| redirect ($routeName, array $parameters=array()) | |
| Helper method that creates an action method result encapsulating redirection. | |
| view ($viewName, array $data=array()) | |
| Helper method that creates an action method result encapsulating presentation object. | |
| ActionBasedController::filterArgumentValue | ( | ReflectionParameter $ | argument | ) | [protected] |
Gets the actual parameter value to be used when invoking action method.
| ReflectionParameter | $argument |
| TraceException | thrown in case when value cannot being obtained |
Definition at line 120 of file ActionBasedController.class.php.
References getActualParameterValue().
Referenced by processAction().
| ActionBasedController::getActualParameterValue | ( | ReflectionParameter $ | argument, | |
| $ | value | |||
| ) | [protected] |
Casts the obtained value to the type expected in action method signature.
This is low-level method. Consider reimplementing ActionBasedController::getClassValue() and ActionBasedController::getArrayValue()
| ReflectionParameter | $argument | |
| mixed | $value |
Definition at line 221 of file ActionBasedController.class.php.
References getArrayValue(), and getClassValue().
Referenced by filterArgumentValue().
| ActionBasedController::getArrayValue | ( | $ | action, | |
| $ | name, | |||
| $ | value | |||
| ) | [protected] |
Casts the parameter value which is expected to be an array according to action method signature.
| string | $action requested action name | |
| string | $name name of the parameter | |
| mixed | $value obtained value |
Definition at line 166 of file ActionBasedController.class.php.
Referenced by getActualParameterValue().
| ActionBasedController::getClassValue | ( | $ | action, | |
| $ | name, | |||
| ReflectionClass $ | class, | |||
| $ | value | |||
| ) | [protected] |
Casts the parameter value which is expected to be an instance of a class according to action method signature.
| string | $action requested action name | |
| string | $name name of the parameter | |
| ReflectionClass | $class | |
| mixed | $value obtained value |
Definition at line 184 of file ActionBasedController.class.php.
Referenced by getActualParameterValue().
| ActionBasedController::getMethodName | ( | $ | action | ) | [protected] |
Gets the name of action method.
This method DOES NOT check the existance of the method
| string | $action requested action |
Definition at line 367 of file ActionBasedController.class.php.
Referenced by handle().
| ActionBasedController::getModel | ( | ) |
Gets the current Model to be passed to presentation layer.
Definition at line 102 of file ActionBasedController.class.php.
Referenced by processResult(), and view().
| ActionBasedController::getTrace | ( | ) |
Gets the current trace.
Definition at line 92 of file ActionBasedController.class.php.
| ActionBasedController::handle | ( | Trace $ | trace | ) |
Runs the controller object to handle the incoming context.
| Trace | $trace trace to handle |
| TraceException | thrown when Trace is missing the required element and thus cannot be handled |
Implements IController.
Definition at line 60 of file ActionBasedController.class.php.
References getMethodName(), handleUnknownAction(), makeActionResult(), processAction(), and processResult().
| ActionBasedController::handleUnknownAction | ( | $ | action | ) | [protected] |
Represents an action method invoked in case when no other action method can be invoked to handle the Trace.
By default this method throws TraceException to notify a calling code that no action method found to handle the Trace
| string|null | $action name of an action that was used when looking up the action method |
| TraceException |
Definition at line 263 of file ActionBasedController.class.php.
Referenced by handle().
| ActionBasedController::makeActionResult | ( | $ | actionResult | ) | [protected] |
Cast the result of action method (of any type) to IActionResult.
The following types are supported:
Definition at line 303 of file ActionBasedController.class.php.
References TypeUtils::getName(), Assert::isUnreachable(), and view().
Referenced by handle().
| ActionBasedController::processAction | ( | $ | action, | |
| ReflectionMethod $ | method | |||
| ) | [protected] |
Look ups for the action method that corresponds the requested action, collects parameter values, invokes the method and wraps its result, if needed.
| string | $action requested action | |
| ReflectionMethod | $method a method that corresponds the action |
Definition at line 280 of file ActionBasedController.class.php.
References filterArgumentValue().
Referenced by handle().
| ActionBasedController::processResult | ( | IActionResult $ | actionResult | ) | [protected] |
Runs the proccess of handing the action method result.
| IActionResult | $actionResult |
Definition at line 241 of file ActionBasedController.class.php.
References getModel(), and IActionResult::handleResult().
Referenced by handle().
| ActionBasedController::redirect | ( | $ | routeName, | |
| array $ | parameters = array() | |||
| ) | [protected] |
Helper method that creates an action method result encapsulating redirection.
| string | $routeName name of the route to use when building an address. Route must be presented in IRouteTable | |
| array | $parameters parameters to pass to Route for building an address |
Definition at line 348 of file ActionBasedController.class.php.
| ActionBasedController::view | ( | $ | viewName, | |
| array $ | data = array() | |||
| ) | [protected] |
Helper method that creates an action method result encapsulating presentation object.
| string | $viewName relative path to a view | |
| array | $data business logic resulting data to be passed to presentation |
Definition at line 328 of file ActionBasedController.class.php.
References getModel().
Referenced by makeActionResult().
| const ActionBasedController::PARAMETER_ACTION = 'action' |
Definition at line 43 of file ActionBasedController.class.php.