Example #1
0
 /**
  * Check if action request, then dispatch the action class.
  *
  *
  * @param string  $actionName
  * @param array   $arguments
  * @return ActionKit\Result result array if there is such an action.
  * */
 public function run($actionName, array $arguments = array(), ActionRequest $request = null)
 {
     if (!Utils::validateActionName($actionName)) {
         throw new InvalidActionNameException("Invalid action name: {$actionName}.");
     }
     /* translate :: into php namespace */
     $class = Utils::toActionClass($actionName);
     /* register results into hash */
     $action = $this->createAction($class, $arguments, $request);
     $action->invoke();
     if (isset($this->serviceContainer['action_logger']) && $action instanceof Loggable) {
         $logger = $this->serviceContainer['action_logger'];
         // how do we call the logger?
         if ($logger instanceof Closure) {
             $logger($action);
         } else {
             if ($logger instanceof ActionLogger) {
                 $logger->log($action);
             }
         }
     }
     if ($moniker = $action->getMoniker()) {
         return $this->results[$moniker] = $action->getResult();
     }
     return $this->results[$actionName] = $action->getResult();
 }