Esempio n. 1
0
 /**
  * @command Malocher\Cqrs\Command\InvokeCommandCommand
  * @param InvokeCommandCommand $command
  */
 public function invokeCommandHandler(InvokeCommandCommand $command)
 {
     print "---- monitoring start -----\n";
     print sprintf("InvokeCommandCommand invoked by %s on %s \n", $command->getMessageClass(), $command->getBusName());
     print sprintf("id:%s, edited:%s, ts:%s, version:%s, payload:%s \n", $command->getMessageVars()['id'], $command->getMessageVars()['edited'], $command->getMessageVars()['timestamp'], $command->getMessageVars()['version'], $command->getMessageVars()['payload']);
     print "---- monitoring ends ------\n";
 }
Esempio n. 2
0
 public function testClosureInvokeCommand()
 {
     $gate = new Gate();
     $gate->enableSystemBus();
     $gate->attach($this->bus);
     $this->bus->mapCommand('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand', function (MockCommand $command) {
         $command->edit();
     });
     $gate->getSystemBus()->mapCommand('Malocher\\Cqrs\\Command\\InvokeCommandCommand', function (InvokeCommandCommand $command) {
         $this->invokeCommandCommand = $command;
     });
     $gate->getSystemBus()->registerEventListener('Malocher\\Cqrs\\Event\\CommandInvokedEvent', function (CommandInvokedEvent $event) {
         $this->commandInvokedEvent = $event;
     });
     $mockCommand = new MockCommand();
     $gate->getBus($this->bus->getName())->invokeCommand($mockCommand);
     $this->assertEquals(true, $mockCommand->isEdited());
     $this->assertInstanceOf('Malocher\\Cqrs\\Command\\InvokeCommandCommand', $this->invokeCommandCommand);
     $this->assertInstanceOf('Malocher\\Cqrs\\Event\\CommandInvokedEvent', $this->commandInvokedEvent);
     $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand', $this->invokeCommandCommand->getMessageClass());
     $this->assertEquals('Malocher\\CqrsTest\\Coverage\\Mock\\Command\\MockCommand', $this->commandInvokedEvent->getMessageClass());
 }
Esempio n. 3
0
 /**
  * {@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;
 }