<?php require_once __DIR__ . '/../bootstrap.php'; // An event listener implements the handle method class MyEventListener implements Broadway\EventHandling\EventListenerInterface { public function handle(Broadway\Domain\DomainMessage $domainMessage) { echo "Got a domain message, yay!\n"; } } // Create the event bus and subscribe the created event listener $eventBus = new Broadway\EventHandling\SimpleEventBus(); $eventListener = new MyEventListener(); $eventBus->subscribe($eventListener); // Create a domain event stream to publish $metadata = new Broadway\Domain\Metadata(array('source' => 'example')); $domainMessage = Broadway\Domain\DomainMessage::recordNow(42, 1, $metadata, new stdClass()); $domainEventStream = new Broadway\Domain\DomainEventStream(array($domainMessage)); // Publish the message, and get output from the event handler \o/ $eventBus->publish($domainEventStream);
class MyEventListener implements Broadway\EventHandling\EventListenerInterface { //public function handle(DivorcedEvent $divorcedEvent) public function handle(Broadway\Domain\DomainMessage $domainMessage) { // var_dump($domainMessage); echo "Do cool things here!\n"; } } //////////////////////////////////////////////////////////////////////////////// //// Here, all the setting up - //// make Store, Bus, //// Instantiate & Subscribe your listener(s), make the Repositories, Command handler // Swap for a real one $eventStore = new \Broadway\EventStore\InMemoryEventStore(); $eventBus = new \Broadway\EventHandling\SimpleEventBus(); // Subscribe your things here $eventListener = new MyEventListener(); $eventBus->subscribe($eventListener); // Setup the command handler $marriageRepository = MarriageRepository::parent($eventStore, $eventBus); $commandHandler = new MarriageCommandHandler($marriageRepository); // Create a command bus and subscribe the command handler at the command bus $commandBus = new \Broadway\CommandHandling\SimpleCommandBus(); $commandBus->subscribe($commandHandler); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Data for the Command & Marriage $generator = new \Broadway\UuidGenerator\Rfc4122\Version4Generator(); // @TODO: FLUSH OUT THESE EXAMPLES $partnerId_1 = $generator->generate(); $partnerId_2 = $generator->generate();