コード例 #1
0
 public function testEventMiddlwareFiresTheSpecificHandledEventWithTheCommandAndResult()
 {
     $eventCommand = $eventResult = null;
     $this->handlerWill($this->returnValue($result = new \stdClass()));
     $this->dispatcher->addListener(CommandEvents::handled(Command::class), function ($e) use(&$eventCommand, &$eventResult) {
         $eventCommand = $e->getCommand();
         $eventResult = $e->getResult();
     });
     $this->bus->handle($command = new Command());
     $this->assertSame($command, $eventCommand);
     $this->assertSame($result, $eventResult);
 }
コード例 #2
0
 /**
  * {@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;
     }
 }