The preferred way to install this extension is through Composer.
Either run
php composer.phar require zelenin/message-bus "~0.0.1"
or add
"zelenin/message-bus": "~0.0.1"
to the require section of your composer.json
$handlers = [
CreatePost::class => new CreatePostHandler($postRepository)
];
$middlewares = [
new HandlerMiddleware(new MemoryLocator($handlers))
];
$commandBus = new MiddlewareBus(new MiddlewareStack($middlewares));
$message = new CreatePost('Post title', 'Post content');
$context = $commandBus->handle($message);
ProviderLocator:
$provider = new AnnotationProvider(__DIR__ . '/src');
if ($isProduction) {
$provider = new CacheProvider(__DIR__ . '/data/handlers-cache.php', $provider);
}
$locator = new ProviderLocator($provider, new ContainerHandlerResolver($container));
return new MiddlewareBus(new MiddlewareStack([
new HandlerMiddleware($locator),
]));
ContainerHandlerResolver
may be used for PSR-11 Container support.
The Message bus uses the immutable Context
to transfer data through middlewares and return it to consumer.
Aleksandr Zelenin, e-mail: [email protected]