Exemplo n.º 1
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration2Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Map a command to a handler
     $this->bus->mapCommand('Iteration\\Iteration2\\Iteration2Command', function (Iteration2Command $command) {
         $command->edit();
         print sprintf("%s says: %s ... Command\n", __METHOD__, $command->getPayload());
         $event = new Iteration2Event('Hello');
         $event->edit();
         $this->bus->publishEvent($event);
     });
     // Register a event to a handler
     $this->bus->registerEventListener('Iteration\\Iteration2\\Iteration2Event', function (Iteration2Event $event) {
         $event->edit();
         print sprintf("%s says: %s ... Event\n", __METHOD__, $event->getPayload());
     });
     // Send a command to the bus
     // Iteration1Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration2Command('Hello'));
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function setUp()
 {
     $this->bus = new MockBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $this->anotherBus = new MockAnotherBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $gate = new Gate();
     $gate->attach($this->bus);
     $gate->attach($this->anotherBus);
 }
Exemplo n.º 3
0
 public function testInvokeCommand__withCallableCommandHandler()
 {
     $this->bus->mapCommand('Malocher\\CqrsTest\\Integration\\Integration3\\Integration3Command', function (Integration3Command $command) {
         $command->edit();
     });
     $Integration3Command = new Integration3Command();
     $this->gate->getBus('test-integration-Integration3-bus')->invokeCommand($Integration3Command);
     $this->assertTrue($Integration3Command->isEdited());
 }
Exemplo n.º 4
0
 /**
  *
  */
 protected function setUp()
 {
     $this->gate = new Gate();
     $this->bus = new Integration2Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     $this->adapter = new AnnotationAdapter();
 }
Exemplo n.º 5
0
 /**
  *
  */
 protected function setUp()
 {
     $this->gate = new Gate();
     $this->bus = new Integration1Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->bus->mapCommand('Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Command', array('alias' => 'Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Handler', 'method' => 'editCommand'));
     $this->bus->registerEventListener('Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Event', array('alias' => 'Malocher\\CqrsTest\\Integration\\Integration1\\Integration1Handler', 'method' => 'editEvent'));
     $this->gate->attach($this->bus);
 }
Exemplo n.º 6
0
 public function exchangecurrencyAction()
 {
     try {
         $exchangeRequest = new ExchangeCurrencyRequest();
         $exchangeRequest->setQuantity(10);
         $exchangeRequest->setCurrencyCode('PLN');
         $exchangeRequest->setIdAcccountIn('1671dd26-8b07-4bb8-a009-f80049c6368f');
         $exchangeRequest->setIdAcccountReturn('1671dd26-8b07-4bb8-a009-f80049c6368f');
         $exchangeCommand = new ExchangeCurrencyCommand($exchangeRequest);
         $this->_commandBus->getBus(DomainBus::NAME)->invokeCommand($exchangeCommand);
     } catch (\Exception $e) {
         var_dump($e->getMessage());
     }
     return new ViewModel();
 }
Exemplo n.º 7
0
 public function testGetBus_ErrorWhenNoDefaultBusIsDefined()
 {
     $this->setExpectedException('Malocher\\Cqrs\\Bus\\BusException');
     $mockBus = new MockBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $anotherBus = new \Malocher\CqrsTest\Coverage\Mock\Bus\MockAnotherBus(new ClassMapCommandHandlerLoader(), new ClassMapEventListenerLoader(), new ClassMapQueryHandlerLoader());
     $this->gate->attach($mockBus);
     $this->gate->attach($anotherBus);
     $this->assertEquals($this->gate->getBus(), $mockBus);
 }
Exemplo n.º 8
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration1Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Map a command to a handler
     $this->bus->mapCommand('Iteration\\Iteration1\\Iteration1Command', array('alias' => 'Iteration\\Iteration1\\Iteration1Handler', 'method' => 'editCommand'));
     // Register a event to a handler
     $this->bus->registerEventListener('Iteration\\Iteration1\\Iteration1Event', array('alias' => 'Iteration\\Iteration1\\Iteration1Handler', 'method' => 'editEvent'));
     // Send a command to the bus
     // Iteration1Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration1Command('Hello'));
 }
Exemplo n.º 9
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration3Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Use of AnnotationAdapter, adapters always us pipe
     $adapter = new AnnotationAdapter();
     $adapter->pipe($this->bus, array('Iteration\\Iteration3\\Iteration3Handler'));
     // See how this affects Iteration3Handler
     // Send a command to the bus
     // Iteration3Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration3Command('Hello'));
 }
Exemplo n.º 10
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration4Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Use of AnnotationAdapter, adapters always us pipe
     $adapter = new AnnotationAdapter();
     $adapter->pipe($this->bus, array('Iteration\\Iteration4\\Iteration4Handler'));
     // Enable the SystemBus and pipe it to some Monitoring
     $this->gate->enableSystemBus();
     $adapter->pipe($this->gate->getSystemBus(), array('Iteration\\Iteration4\\Iteration4Monitor'));
     // Send a command to the bus
     // Iteration4Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration4Command('Hello'));
 }
Exemplo n.º 11
0
 /**
  * load bus
  *
  * @param $busClass
  * @return mixed
  * @throws ConfigurationException
  */
 protected function loadBus($busClass)
 {
     $bus = new $busClass();
     if ($bus instanceof CommandHandlerLoaderAwareInterface) {
         if (is_null($this->getCommandHandlerLoader())) {
             throw ConfigurationException::initializeError('CommandHandlerLoaderInterface not initialized. Create a new CommandHandlerLoader() and pass it to setCommandHandlerLoader()');
         }
         $bus->setCommandHandlerLoader($this->commandHandlerLoader);
     }
     if ($bus instanceof EventListenerLoaderAwareInterface) {
         if (is_null($this->getEventListenerLoader())) {
             throw ConfigurationException::initializeError('EventListenerLoaderInterface not initialized. Create a new EventListenerLoader() and pass it to setEventListenerLoader()');
         }
         $bus->setEventListenerLoader($this->eventListenerLoader);
     }
     if ($bus instanceof QueryHandlerLoaderAwareInterface) {
         if (is_null($this->getQueryHandlerLoader())) {
             throw ConfigurationException::initializeError('QueryHandlerLoaderInterface not initialized. Create a new QueryHandlerLoader() and pass it to setQueryHandlerLoader()');
         }
         $bus->setQueryHandlerLoader($this->queryHandlerLoader);
     }
     $this->gate->attach($bus);
     return $bus;
 }
Exemplo n.º 12
0
 /**
  * {@inheritDoc}
  */
 public function publishEvent(EventInterface $event)
 {
     // Check if event exists after invoking the PublishEventCommand because
     // the PublishEventCommand tells that a event is dispatched but does not care
     // if it succeeded. Later the EventPublishedEvent can be used to check if a
     // event succeeded.
     if (!is_null($this->gate->getSystemBus())) {
         $publishEventCommand = new PublishEventCommand();
         $publishEventCommand->setMessageClass(get_class($event));
         $publishEventCommand->setMessageVars($event->getMessageVars());
         $publishEventCommand->setBusName($this->getName());
         $this->gate->getSystemBus()->invokeCommand($publishEventCommand);
     }
     try {
         $response = $this->bus->publishEvent($event);
         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 EventPublishedEvent here! If for example a event could not be dispatched
     // because it does not exist in the eventListenerMap[<empty>] this Event would never
     // be dispatched!
     if (!is_null($this->gate->getSystemBus())) {
         $eventPublishedEvent = new EventPublishedEvent();
         $eventPublishedEvent->setMessageClass(get_class($event));
         $eventPublishedEvent->setMessageVars($event->getMessageVars());
         $eventPublishedEvent->setBusName($this->getName());
         $this->gate->getSystemBus()->publishEvent($eventPublishedEvent);
     }
     return $response;
 }
Exemplo n.º 13
0
 public function testPublishEvent()
 {
     $gate = new Gate();
     $gate->attach($this->bus);
     $this->bus->registerEventListener('Malocher\\CqrsTest\\Coverage\\Mock\\Event\\MockEvent', function (MockEvent $event) {
         $event->edit();
     });
     $mockEvent = new MockEvent();
     $this->bus->publishEvent($mockEvent);
     $this->assertEquals(true, $mockEvent->isEdited());
 }
Exemplo n.º 14
0
 public function testInvokeNonMappedEvent()
 {
     $gate = new Gate();
     $gate->enableSystemBus();
     $mockEvent = new MockEvent();
     $this->assertFalse($gate->getSystemBus()->publishEvent($mockEvent));
 }
 public function testUninstall()
 {
     $this->fs->ensureDirectoryExists($this->pluginDir);
     $installer = new GingerInstaller($this->io, $this->composer);
     $repository = new ComposerRepositoryMock();
     $package = new Package('gingerwfms/wf-configurator-backend', '1.0.0', '1.0.0');
     $package->setType('ginger-backend-plugin');
     $package->setExtra(array('plugin-namespace' => 'WfConfiguratorBackend'));
     $repository->addPackage($package);
     $gate = new Gate();
     $mockBus = new CqrsBusMock();
     $pluginNamespace = '';
     $pluginName = '';
     $pluginType = '';
     $pluginVersion = '';
     $mockBus->mapCommand('GingerPluginInstaller\\Cqrs\\UninstallPluginCommand', function (UninstallPluginCommand $command) use(&$pluginNamespace, &$pluginName, &$pluginType, &$pluginVersion) {
         $pluginNamespace = $command->getPluginNamespace();
         $pluginName = $command->getPluginName();
         $pluginType = $command->getPluginType();
         $pluginVersion = $command->getPluginVersion();
     });
     $gate->attach($mockBus);
     $gate->setDefaultBusName($mockBus->getName());
     Bootstrap::getServiceManager()->setAllowOverride(true);
     Bootstrap::getServiceManager()->setService('malocher.cqrs.gate', $gate);
     $installer->uninstall($repository, $package);
     $this->assertSame('WfConfiguratorBackend', $pluginNamespace);
     $this->assertSame('gingerwfms/wf-configurator-backend', $pluginName);
     $this->assertSame('ginger-backend-plugin', $pluginType);
     $this->assertSame('1.0.0', $pluginVersion);
 }