Example #1
0
 /**
  * Execute the handler
  *
  * @param KCommandInterface         $command    The command
  * @param KCommandChainInterface    $chain      The chain executing the command
  * @return mixed|null If a handler breaks, returns the break condition. NULL otherwise.
  */
 public function execute(KCommandInterface $command, KCommandChainInterface $chain)
 {
     $parts = explode('.', $command->getName());
     $method = '_' . $parts[0] . ucfirst($parts[1]);
     if (method_exists($this, $method)) {
         return $this->{$method}($command);
     }
 }
Example #2
0
 /**
  * Command handler
  *
  * @param KCommandInterface         $command    The command
  * @param KCommandChainInterface    $chain      The chain executing the command
  * @return mixed If a handler breaks, returns the break condition. Returns the result of the handler otherwise.
  */
 public function execute(KCommandInterface $command, KCommandChainInterface $chain)
 {
     $parts = explode('.', $command->getName());
     $method = '_' . $parts[0] . ucfirst($parts[1]);
     if ($parts[0] == 'action') {
         $result = $this->{$method}($command);
     } else {
         $result = parent::execute($command, $chain);
     }
     return $result;
 }
Example #3
0
 /**
  * Command handler.
  *
  * @param KCommandInterface      $command The command.
  * @param KCommandChainInterface $chain   The chain executing the command.
  * @return mixed If a handler breaks, returns the break condition. Returns the result of the handler otherwise.
  */
 public final function execute(KCommandInterface $command, KCommandChainInterface $chain)
 {
     $action = $command->getName();
     foreach ($this->__queue as $logger) {
         if (in_array($action, $logger->getActions())) {
             $object = $logger->getActivityObject($command);
             if ($object instanceof KModelEntityInterface) {
                 $subject = $logger->getActivitySubject($command);
                 $logger->log($action, $object, $subject);
             }
         }
     }
 }
 /**
  * Command handler
  *
  * Only handles before.action commands to check authorization rules.
  *
  * @param KCommandInterface         $command    The command
  * @param KCommandChainInterface    $chain      The chain executing the command
  * @throws  KControllerExceptionRequestForbidden      If the user is authentic and the actions is not allowed.
  * @throws  KControllerExceptionRequestNotAuthorized  If the user is not authentic and the action is not allowed.
  * @return  boolean Return TRUE if action is permitted. FALSE otherwise.
  */
 public function execute(KCommandInterface $command, KCommandChainInterface $chain)
 {
     $parts = explode('.', $command->getName());
     if ($parts[0] == 'before') {
         $action = $parts[1];
         if ($this->canExecute($action) === false) {
             $message = 'Action ' . ucfirst($action) . ' Not Allowed';
             if ($this->getUser()->isAuthentic()) {
                 if (!$this->getUser()->isEnabled()) {
                     $message = 'Account disabled';
                 }
                 throw new KControllerExceptionRequestForbidden($message);
             } else {
                 throw new KControllerExceptionRequestNotAuthorized($message);
             }
             return false;
         }
     }
     return true;
 }
Example #5
0
 /**
  * Attach a command to the chain
  *
  * The priority parameter can be used to override the command priority with
  * enqueing the command.
  *
  * @param   object      A KCommand object
  * @param   integer     The command priority, usually between 1 (high priority) and 5 (lowest),
  *                      default is 3. If no priority is set, the command priority will be used
  *                      instead.
  * @return KCommandChain
  */
 public function enqueue(KCommandInterface $cmd, $priority = null)
 {
     $priority = is_int($priority) ? $priority : $cmd->getPriority();
     return parent::enqueue($cmd, $priority);
 }
Example #6
0
 /**
  * Command handler
  *
  * @param KCommandInterface         $command    The command
  * @param KCommandChainInterface    $chain      The chain executing the command
  * @return mixed|null If a handler breaks, returns the break condition. NULL otherwise.
  */
 public function execute(KCommandInterface $command, KCommandChainInterface $chain)
 {
     $type = '';
     $package = '';
     $subject = '';
     if ($command->getSubject()) {
         $identifier = $command->getSubject()->getIdentifier()->toArray();
         $package = $identifier['package'];
         if ($identifier['path']) {
             $type = array_shift($identifier['path']);
             $subject = $identifier['name'];
         } else {
             $type = $identifier['name'];
         }
     }
     $parts = explode('.', $command->getName());
     $when = array_shift($parts);
     // Before or After
     $name = KStringInflector::implode($parts);
     // Read Dispatch Select etc.
     // Create Specific and Generic event names
     $event_specific = 'on' . ucfirst($when) . ucfirst($package) . ucfirst($subject) . ucfirst($type) . $name;
     $event_generic = 'on' . ucfirst($when) . ucfirst($type) . $name;
     // Clone the context
     if ($this->_immutable) {
         $event = clone $command;
     } else {
         $event = $command;
     }
     // Create event object to check for propagation
     $event = $this->getEventPublisher()->publishEvent($event_specific, $event->getAttributes(), $event->getSubject());
     // Ensure event can be propagated and event name is different
     if ($event->canPropagate() && $event_specific != $event_generic) {
         $event->setName($event_generic);
         $this->getEventPublisher()->publishEvent($event);
     }
 }
Example #7
0
 /**
  * Get the activity subject.
  *
  * The activity subject is the identifier of the object that executes the action.
  *
  * @param KCommandInterface $command The command.
  * @return KObjectIdentifier The activity subject.
  */
 public function getActivitySubject(KCommandInterface $command)
 {
     return $command->getSubject()->getIdentifier();
 }