public function testEventMiddlewareFiresTheCommandSpecificReceivedEvent() { $eventCommand = null; $this->dispatcher->addListener(CommandEvents::received(Command::class), function ($e) use(&$eventCommand) { $eventCommand = $e->getCommand(); }); $this->bus->handle($command = new Command()); $this->assertSame($command, $eventCommand); }
/** * {@inheritdoc} */ public function execute($command, callable $next) { try { $this->dispatch(CommandEvents::RECEIVED, new CommandReceived($command)); $this->dispatch(CommandEvents::received($command), new CommandReceived($command)); $result = $next($command); $this->dispatch(CommandEvents::HANDLED, new CommandHandled($command, $result)); $this->dispatch(CommandEvents::handled($command), new CommandHandled($command, $result)); return $result; } catch (\Exception $e) { $this->dispatch(CommandEvents::FAILED, new CommandFailed($command, $e)); $this->dispatch(CommandEvents::failed($command), new CommandFailed($command, $e)); throw $e; } }