PHP code example of core-framework / dispatcher

1. Go to this page and download the library: Download core-framework/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/ */

    

core-framework / dispatcher example snippets


$dispatcher = new Dispatcher();

$dispatcher->on('eventFoo', function() { echo 'foo';});

class TestEventListener implements ListenerInterface
{
    /**
     * @var EventInterface
     */
    public $calledEvent;
    /**
     * @var string
     */
    public $eventName;
    /**
     * @var DispatcherInterface
     */
    public $dispatcher;

    public function __invoke(EventInterface $event, string $eventName = null, DispatcherInterface $dispatcher = null)
    {
        $this->calledEvent = $event;
        $this->eventName = $eventName;
        $this->dispatcher = $dispatcher;
    }
}

$subscriber = new Subscriber();
$dispatcher->addSubscriber($subscriber);