PHP code example of antidot-fw / event-dispatcher

1. Go to this page and download the library: Download antidot-fw/event-dispatcher 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/ */

    

antidot-fw / event-dispatcher example snippets



/** @var \Psr\Container\ContainerInterface $container */
$container->set('config', [
    'app-events' => [
        'event-listeners' => [
//            SomeEvent::class => [
            'some.event' => [
                SomeEventListener::class,
                SomeEventOtherListener::class,
            ]
        ]
    ]
]);



use Antidot\Event\Container\EventDispatcherFactory;
use Psr\EventDispatcher\EventDispatcherInterface;

$factory = new EventDispatcherFactory();

$eventDispatcher = $factory->__invoke($container);
$container->set(EventDispatcherInterface::class, $eventDispatcher);



use Antidot\Event\Container\AsyncEventDispatcherFactory;
use Psr\EventDispatcher\EventDispatcherInterface;

$factory = new AsyncEventDispatcherFactory();

$eventDispatcher = $factory->__invoke($container);
$container->set(EventDispatcherInterface::class, $eventDispatcher);



use Psr\EventDispatcher\EventDispatcherInterface;

/** @var \Psr\Container\ContainerInterface $container */
$eventDispatcher = $container->get(EventDispatcherInterface::class);

$eventDispatcher->dispatch(SomeEvent::occur());



use Psr\EventDispatcher\EventDispatcherInterface;
use React\EventLoop\Loop;

/** @var \Psr\Container\ContainerInterface $container */
$eventDispatcher = $container->get(EventDispatcherInterface::class);

$eventDispatcher->dispatch(SomeEvent::occur());

Loop::run()