Example #1
0
 private function newSequentialCommandBusWith($commandType, $service)
 {
     $locator = new MemoryCommandHandlerLocator();
     $locator->register($commandType, $service);
     return new SequentialCommandBus($locator);
 }
Example #2
0
class InventoryConsoleOutputListener
{
    public function onInventoryItemCreated(InventoryItemCreated $event)
    {
        echo "Creating: " . $event->id . "\n";
    }
    public function onInventoryItemRenamed(InventoryItemRenamed $event)
    {
        echo "new name for " . $event->id . ": " . $event->name . "\n";
    }
    public function onInventoryItemDeactivated(InventoryItemDeactivated $event)
    {
        echo "Deactivated " . $event->id . "\n";
    }
}
$listener = new InventoryConsoleOutputListener();
$eventHandlerLocator = new Eventing\MemoryEventHandlerLocator();
$eventHandlerLocator->register($listener);
$eventStore = new EventStore\OptimisticLocking\OptimisticLockingEventStore(new EventStore\OptimisticLocking\MemoryStorage(), new ReflectionSerializer());
$eventBus = new Eventing\SynchronousInProcessEventBus($eventHandlerLocator);
$repository = new EventStore\EventSourceRepository($eventStore, $eventBus);
$inventoryHandler = new InventoryHandler($repository);
$commandHandlerLocator = new Commanding\MemoryCommandHandlerLocator();
$commandHandlerLocator->register('EventSourced\\CreateInventoryItem', $inventoryHandler);
$commandHandlerLocator->register('EventSourced\\ChangeInventoryName', $inventoryHandler);
$commandHandlerLocator->register('EventSourced\\DeactivateInventoryItem', $inventoryHandler);
$commandBus = new Commanding\SequentialCommandBus($commandHandlerLocator);
$id = Uuid::uuid4();
$commandBus->handle(new CreateInventoryItem(array('id' => $id)));
$commandBus->handle(new ChangeInventoryName(array('id' => $id, 'newName' => 'test')));
$commandBus->handle(new DeactivateInventoryItem(array('id' => $id)));