Home  Support  API

ActionBasedController Class Reference
[Mvc]


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.

Inheritance diagram for ActionBasedController:
Inheritance graph

List of all members.

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.

Member Function Documentation

ActionBasedController::filterArgumentValue ( ReflectionParameter $  argument  )  [protected]

Gets the actual parameter value to be used when invoking action method.

Parameters:
ReflectionParameter $argument
Exceptions:
TraceException thrown in case when value cannot being obtained
Returns:
mixed

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()

Parameters:
ReflectionParameter $argument
mixed $value
Returns:
mixed

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.

Parameters:
string $action requested action name
string $name name of the parameter
mixed $value obtained value
Returns:
array|null

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.

Parameters:
string $action requested action name
string $name name of the parameter
ReflectionClass $class
mixed $value obtained value
Returns:
object|null

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

Parameters:
string $action requested action
Returns:
string

Definition at line 367 of file ActionBasedController.class.php.

Referenced by handle().

ActionBasedController::getModel (  ) 

Gets the current Model to be passed to presentation layer.

Returns:
Model

Definition at line 102 of file ActionBasedController.class.php.

Referenced by processResult(), and view().

ActionBasedController::getTrace (  ) 

Gets the current trace.

Returns:
Trace

Definition at line 92 of file ActionBasedController.class.php.

ActionBasedController::handle ( Trace trace  ) 

Runs the controller object to handle the incoming context.

Parameters:
Trace $trace trace to handle
Exceptions:
TraceException thrown when Trace is missing the required element and thus cannot be handled
Returns:
void

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

Parameters:
string|null $action name of an action that was used when looking up the action method
Exceptions:
TraceException 
Returns:
IActionResult

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:

Returns:
IActionResult

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.

Parameters:
string $action requested action
ReflectionMethod $method a method that corresponds the action
Returns:
mixed result that may be processed by ActionBasedController::makeActionResult()

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.

Parameters:
IActionResult $actionResult
Returns:
void

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.

Parameters:
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
Returns:
RedirectToRouteResult

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.

Parameters:
string $viewName relative path to a view
array $data business logic resulting data to be passed to presentation
Returns:
ViewResult

Definition at line 328 of file ActionBasedController.class.php.

References getModel().

Referenced by makeActionResult().


Member Data Documentation

Definition at line 43 of file ActionBasedController.class.php.


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