disasterdrop/silex-simple-bus-provider

Silex Provider for Command bus and Event bus Features with the SimpleBus/MessageBus

v1.0 2017-09-01 07:41 UTC

This package is not auto-updated.

Last update: 2024-04-22 05:06:58 UTC


README

By Sebastian Hübner

This is an Silex Provider for the SimpleBus/MessageBus by Matthias Noback

With this Provider you can register new Events and CommandHandlers within your silex application.

Event Bus

Register Event Bus

$app->register(new \Disasterdrop\SimpleBusProvider\Provider\EventBusProvider());

Add Subscriber to the Event Bus

// Event Bus
$app['eventSubscribers'] = function ($app) {
    $subscribers = [
        SomeEventHappens::class => [
            function ($message) use ($app) {
                $eventSubscriber = new SomeEventHappens($app['someService']);
                return $eventSubscriber->notify($message);
            }
        ]
    ];
    return $subscribers;
};

Command Handler

Register Command Handler

$app->register(new Disasterdrop\SimpleBusProvider\Provider\CommandBusProvider());

Add Handlers to the Command Bus

// Command Bus
$app['commandHandlers'] = function ($app) {
    $handlers = [
        SomeCommand::class => function ($command) use ($app) {
            $commandHandler = new SomeCommandHandler($app['pollWriteRepository'], $app['eventBus']);
            return $commandHandler->handle($command);
        },
    ];
    return $handlers;
};