Psr 14 Event dispatcher implementation.
Using composer
composer require antidot-fw/event-dispatcher
it install the library automatically
<?php
/** @var \Psr\Container\ContainerInterface $container */
$container->set('config', [
'app-events' => [
'event-listeners' => [
// SomeEvent::class => [
'some.event' => [
SomeEventListener::class,
SomeEventOtherListener::class,
]
]
]
]);
<?php
use Antidot\Event\Container\EventDispatcherFactory;
use Psr\EventDispatcher\EventDispatcherInterface;
$factory = new EventDispatcherFactory();
$eventDispatcher = $factory->__invoke($container);
$container->set(EventDispatcherInterface::class, $eventDispatcher);
composer require react/event-loop
<?php
use Antidot\Event\Container\AsyncEventDispatcherFactory;
use Psr\EventDispatcher\EventDispatcherInterface;
$factory = new AsyncEventDispatcherFactory();
$eventDispatcher = $factory->__invoke($container);
$container->set(EventDispatcherInterface::class, $eventDispatcher);
<?php
use Psr\EventDispatcher\EventDispatcherInterface;
/** @var \Psr\Container\ContainerInterface $container */
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->dispatch(SomeEvent::occur());
<?php
use Psr\EventDispatcher\EventDispatcherInterface;
use React\EventLoop\Loop;
/** @var \Psr\Container\ContainerInterface $container */
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->dispatch(SomeEvent::occur());
Loop::run()