Esempio n. 1
0
 private function createInMemoryEventBusWith($eventHandler)
 {
     $locator = new MemoryEventHandlerLocator();
     $locator->register($eventHandler);
     return new SynchronousInProcessEventBus($locator);
 }
Esempio n. 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)));