/** * Command handler * * This functions returns void to prevent is from breaking the chain. * * @param string $name The command name * @param object $context The command context * @return void */ public function execute($name, CommandContext $context) { $type = ''; if ($context->getSubject()) { $identifier = clone $context->getSubject()->getIdentifier(); if ($identifier->path) { $type = array_shift($identifier->path); } else { $type = $identifier->name; } } $parts = explode('.', $name); $name = 'on' . ucfirst(array_shift($parts)) . ucfirst($type) . StringInflector::implode($parts); $event = new Event(clone $context); $event->setTarget($context->getSubject()); $this->getEventDispatcher()->dispatchEvent($name, $event); }
/** * Command handler * * This function translates the command name to a command handler function of the format '_beforeController[Command]' * or '_afterController[Command]. Command handler functions should be declared protected. * * @param string $name The command name * @param CommandContext $context The command context * @return boolean Always returns TRUE */ public final function execute($name, CommandContext $context) { $identifier = clone $context->getSubject()->getIdentifier(); $type = array_shift($identifier->path); $parts = explode('.', $name); $method = '_' . $parts[0] . ucfirst($type) . ucfirst($parts[1]); if (method_exists($this, $method)) { $this->{$method}($context); } return true; }
/** * Command handler * * @param string $name The command name * @param CommandContext $context The command context * * @return mixed Method result if the method exsist, NULL otherwise. */ public function execute($name, CommandContext $context) { $type = ''; $result = null; if ($context->getSubject()) { $identifier = clone $context->getSubject()->getIdentifier(); if ($identifier->path) { $type = array_shift($identifier->path); } else { $type = $identifier->name; } } $parts = explode('.', $name); $method = !empty($type) ? '_' . $type . ucfirst(StringInflector::implode($parts)) : '_' . lcfirst(StringInflector::implode($parts)); //If the method exists call the method and return the result if (in_array($method, $this->getMethods())) { $result = $this->{$method}($context); } return $result; }
/** * Command handler * * This function translates the command name that starts with 'action' to a command handler function of the format * '_action[Action]' * * @param string $name The command name * @param CommandContext $context The command context * @return boolean Can return both true or false. */ public function execute($name, CommandContext $context) { $this->setMixer($context->getSubject()); $parts = explode('.', $name); if ($parts[0] == 'action') { $method = '_action' . ucfirst($parts[1]); if (method_exists($this, $method)) { return $this->{$method}($context); } } return parent::execute($name, $context); }
/** * Command handler * * This function translated the command name to a command handler function of the format '_before[Command]' or * '_after[Command]. Command handler functions should be declared protected. * * @param string $name The command name * @param CommandContext $context The command context * * @return mixed Method result if the method exists, NULL otherwise. */ public function execute($name, CommandContext $context) { $result = null; $identifier = clone $context->getSubject()->getIdentifier(); $type = array_pop($identifier->path); $parts = explode('.', $name); $method = '_' . $parts[0] . ucfirst($type) . ucfirst($parts[1]); //If the method exists call the method and return the result if (method_exists($this, $method)) { $result = $this->{$method}($context); } return $result; }