PHP code example of elephox / events

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

    

elephox / events example snippets




use Elephox\Events\EventBus;

$bus = new EventBus();
$subscription = $bus->subscribe('test', function ($data) {
    echo 'test event: ' . $data;
});

$bus->publish('test', 'test data'); // "test event: test data"

$bus->unsubscribe($subscription);

$bus->publish('test', 'test data'); // no output