/** * {@inheritDoc} */ public function invokeCommand(CommandInterface $command) { $commandClass = get_class($command); // InvokeCommandCommand first! Because a commandClass _IS_ actually invoked. if (!is_null($this->gate->getSystemBus())) { $invokeCommandCommand = new InvokeCommandCommand(); $invokeCommandCommand->setMessageClass(get_class($command)); $invokeCommandCommand->setMessageVars($command->getMessageVars()); $invokeCommandCommand->setBusName($this->getName()); $this->gate->getSystemBus()->invokeCommand($invokeCommandCommand); } try { $response = $this->bus->invokeCommand($command); if ($response === false) { return false; } } catch (BusException $ex) { //throw it again throw $ex; } catch (\Exception $ex) { throw BusException::defaultBusError($ex->getMessage(), null, $ex); } // Dispatch the CommandInvokedEvent here! If for example a command could not be invoked // because it does not exist in the commandHandlerMap[<empty>] this Event would never // be dispatched! if (!is_null($this->gate->getSystemBus())) { $commandInvokedEvent = new CommandInvokedEvent(); $commandInvokedEvent->setMessageClass(get_class($command)); $commandInvokedEvent->setMessageVars($command->getMessageVars()); $commandInvokedEvent->setBusName($this->getName()); $this->gate->getSystemBus()->publishEvent($commandInvokedEvent); } return $response; }