Requirements
-
PHP
~8.4.1 || ~8.5.0 -
webware/message-bus^0.1.0- not installed automatically by this package (it's arequire-devdependency here, used only by the test suite). Your application must require it directly. -
phly/phly-event-dispatcher^1.5.0
Installation
composer require webware/messagebus-event webware/message-bus
Wiring
This package ships a Webware\MessageBus\Event\ConfigProvider. Auto-registration is handled by the
laminas/laminas-component-installer Composer
plugin, which reads the extra.laminas.config-provider entry in composer.json; plain
laminas/laminas-config-aggregator only merges config arrays and does not register providers itself.
To wire it manually, merge it with webware/message-bus's own ConfigProvider when building your
application config, then build a Laminas\ServiceManager\ServiceManager from the merged config:
use Laminas\ServiceManager\ServiceManager;
$config = [];
foreach (
[
Webware\MessageBus\ConfigProvider::class,
Webware\MessageBus\Event\ConfigProvider::class,
// ...your own config providers
] as $provider
) {
$config = array_merge_recursive($config, (new $provider())());
}
$container = new ServiceManager($config['dependencies']);
$container->setService('config', $config);
Once wired, resolving Webware\MessageBus\MessageBusInterface from the container gives you a bus whose
default middleware pipeline dispatches CommandPreHandleEvent before a command handler runs, and
CommandPostHandleEvent after it completes. Query events are not wired by default - see
Usage Examples to enable them.
Registering Listeners
Listeners are configured under the listeners and listener_providers keys, read by
Webware\MessageBus\Event\Container\ListenerProviderAggregateFactory:
return [
'listeners' => [
Webware\MessageBus\Event\Command\CommandPostHandleEvent::class => [
// a service id resolved from the container, or a plain callable/class-string
MyListener::class,
// a shape entry supporting an explicit priority (higher runs first)
['listener' => MyOtherListener::class, 'priority' => 10],
],
],
'listener_providers' => [
// service ids of PSR-14 ListenerProviderInterface implementations
MyCustomListenerProvider::class,
],
];
See the API Reference for the full config shape.