/** * 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; } } }