PHP code example of disasterdrop / silex-simple-bus-provider

1. Go to this page and download the library: Download disasterdrop/silex-simple-bus-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

disasterdrop / silex-simple-bus-provider example snippets


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

// 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 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;
};