PHP code example of symbiotic / event-dispatcher-composite

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

    

symbiotic / event-dispatcher-composite example snippets



/**
 * @var Psr\EventDispatcher\ListenerProviderInterface $coreProvider
 * @var Psr\EventDispatcher\ListenerProviderInterface $appProvider
 **/
$core_dispatcher = new MyEventDispatcher($coreProvider);
$app_dispatcher = new MyEventDispatcher($appProvider);

$dispatcher = new  \Symbiotic\Event\CompositeEventDispatcher();
// we add several dispatchers for processing at once
$dispatcher->attach($core_dispatcher);
$dispatcher->attach($app_dispatcher);


// Now the event will be processed by several dispatchers at once

$event = $dispatcher->dispatch(new MyEvent());




/**
 * @var Psr\EventDispatcher\ListenerProviderInterface $core_provider
 * @var Psr\EventDispatcher\ListenerProviderInterface $app_provider
 * @var Psr\EventDispatcher\ListenerProviderInterface $compositeProvider
 **/
$core_provider = new ListenerProvider();
$app_provider = new ListenerProvider();
// adding listeners to providers... 

/**
 * @var Psr\EventDispatcher\ListenerProviderInterface|\Symbiotic\Event\CompositeListenersProvider $compositeProvider
 **/
$compositeProvider = new \Symbiotic\Event\CompositeListenersProvider();
$compositeProvider->attach($core_provider);
$compositeProvider->attach($app_provider);

/**
 * @var Psr\EventDispatcher\EventDispatcherInterface $dispatcher
 **/
$dispatcher = new MyEventDispatcher($compositeProvider);
 
$event = $dispatcher->dispatch(new MyEvent());