/**
  * Invoke a command by calling all the registered callbacks
  *
  * @param  string|KCommandInterface  $command    The command name or a KCommandInterface object
  * @param  array|Traversable         $attributes An associative array or a Traversable object
  * @param  KObjectInterface          $subject    The command subject
  * @return mixed|null If a callback break, returns the break condition. NULL otherwise.
  */
 public function invokeCallbacks($command, $attributes = null, $subject = null)
 {
     //Make sure we have an command object
     if (!$command instanceof KCommandInterface) {
         if ($attributes instanceof KCommandInterface) {
             $name = $command;
             $command = $attributes;
             $command->setName($name);
         } else {
             $command = new KCommand($command, $attributes, $subject);
         }
     }
     foreach ($this->getCommandCallbacks($command->getName()) as $handler) {
         $method = $handler['method'];
         $params = $handler['params'];
         if (is_string($method)) {
             $result = $this->invokeCommandCallback($method, $command->append($params));
         } else {
             $result = $method($command->append($params));
         }
         if ($result !== null && $result === $this->getBreakCondition()) {
             return $result;
         }
     }
 }
Exemple #2
0
 /** 
  * Constructor.
  * 
  * @param mixed $dispatcher A dispatcher
  * @param array $config     An optional KConfig object with configuration options.
  * 
  * @return void
  */
 public function __construct($dispatcher = null, $config = array())
 {
     $config = new KConfig($config);
     parent::__construct($config);
     $this->_name = $config->name;
     KService::get('plg:contentfilter.chain')->addFilter($this);
 }
Exemple #3
0
    /**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional KConfig object with configuration options
     * @return void
     */
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'dispatcher'   => KFactory::get('koowa:event.dispatcher')
        ));

        parent::_initialize($config);
    }
 /**
  * Command handler
  * 
  * @param   string      The command name
  * @param   object      The command context
  * @return  boolean     Can return both true or false.  
  */
 public function execute($name, KCommandContext $context)
 {
     $parts = explode('.', $name);
     //Check the token
     if ($parts[0] == 'before' && $context->caller->isDispatched()) {
         if (!$this->checkToken()) {
             throw new KControllerException('Invalid token or session time-out', KHttpResponse::FORBIDDEN);
         }
     }
     //Execute the command
     if (parent::execute($name, $context) == false) {
         throw new KControllerException(ucfirst($context->action) . ' action not allowed', KHttpResponse::FORBIDDEN);
     }
     return true;
 }
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   object  An optional KConfig object with configuration options
  * @return void
  */
 protected function _initialize(KConfig $config)
 {
     $config->append(array('dispatcher' => $this->getService('koowa:event.dispatcher')));
     parent::_initialize($config);
 }
Exemple #6
0
 /**
  * Searches a repository to see if it behave as.
  *
  * If a method has the form of is[Behavior Name] it check if the repository behave
  *
  * @param string $method The mising method
  * @param array  $args   Method arguments
  *
  * @return bool|mixed
  */
 public function __call($method, $args)
 {
     // If the method is of the form is[Bahavior] handle it.
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         if ($this->hasBehavior(strtolower($parts[1]))) {
             return true;
         }
         return false;
     }
     return parent::__call($method, $args);
 }
Exemple #7
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   object  An optional KConfig object with configuration options
  * @return void
  */
 protected function _initialize(KConfig $config)
 {
     $config->append(array('event_dispatcher' => null));
     parent::_initialize($config);
 }