PHP code example of gianarb / fast-event-manager

1. Go to this page and download the library: Download gianarb/fast-event-manager 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/ */

    

gianarb / fast-event-manager example snippets



use FastEventManager\EventManager;

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    // DO STUFF
});

$assert = false;
$eventManager->trigger("/post-save/", $assert);

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    echo "Hi";
}, 100);

$eventManager->attach("post-save", function ($assertArg) {
    echo " dev!";
}, 10);

$eventManager->trigger("/post-save/");

// output "Hi dev!"

$eventManager = new EventManager();

$eventManager->attach("post-save", function ($assertArg) {
    echo "Hi";
});

$eventManager->attach("pload", function ($assertArg) {
    echo " none!";
});

$eventManager->attach("post-load", function ($assertArg) {
    echo " dev!";
});

$eventManager->trigger("/post-(save|load)/i", $assert);

// output "Hi dev!"

$eventManager = new EventManager();
$count = 0;
$eventManager->attach("post", function () use (&$count) {
    $count++;
}, 100);
$eventManager->attach("post", function () use (&$count) {
    throw new \Exception();
}, 110);
$eventManager->attach("post", function () use (&$count) {
    $count++;
}, 120);
try {
    $eventManager->trigger("/post/");
} catch (\Exception $exc) {
    // STOP!
}