Beispiel #1
0
 /**
  * Execute an action by triggering a method in the derived class.
  *
  * @param   string                      $action  The action to execute
  * @param   ControllerContext $context A command context object
  * @throws  Exception
  * @throws  \BadMethodCallException
  * @return  mixed|bool The value returned by the called method, false in error case.
  */
 public function execute($action, ControllerContext $context)
 {
     $action = strtolower($action);
     //Retrieve the context name and subject
     $subject = $context->getSubject();
     $name = $context->getName();
     //Execute the action
     if ($this->invokeCommand('before.' . $action, $context) !== false) {
         $method = '_action' . ucfirst($action);
         if (!method_exists($this, $method)) {
             if (!$this->isMixedMethod($action)) {
                 throw new ControllerExceptionActionNotImplemented("Can't execute '{$action}', method: '{$method}' does not exist");
             } else {
                 $context->result = parent::__call($action, array($context));
             }
         } else {
             $context->result = $this->{$method}($context);
         }
         $this->invokeCommand('after.' . $action, $context);
     }
     //Reset the context
     $context->setSubject($subject);
     $context->setName($name);
     return $context->result;
 }