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