PHP code example of activecollab / eventsdispatcher

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

    

activecollab / eventsdispatcher example snippets




namespace MyApp;

use ActiveCollab\EventsDispatcher\EventsDispatcher;
use ActiveCollab\EventsDispatcher\Test\Fixtures\LicenseRenewedEvent\LicenseRenewedEventInterface;

$dispatcher = new EventsDispatcher();
$dispatcher->listen(LicenseRenewedEventInterface::class, function (LicenseRenewedEventInterface $event) {
    print "License {$event->getLicenseKey()} has been renewed\n";
});



namespace MyApp;

use ActiveCollab\EventsDispatcher\EventsDispatcher;
use ActiveCollab\EventsDispatcher\Events\EventInterface;

$dispatcher = new EventsDispatcher();
$dispatcher->listen(EventInterface::class, function (EventInterface $event) {
    print "Event " . get_class($event) . " handled\n";
});



namespace MyApp;

use ActiveCollab\EventsDispatcher\EventsDispatcher;
use ActiveCollab\EventsDispatcher\Test\Fixtures\LicenseRenewedEvent\LicenseRenewedEvent;

$dispatcher = new EventsDispatcher();
$dispatcher->trigger(new LicenseRenewedEvent(
    '123',
    '2016-12-31',
    '2017-12-31',
    699.0
));