PHP code example of shieldon / event-dispatcher

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

    

shieldon / event-dispatcher example snippets


composer 



/**
 * @param string        $name      The name of an event.
 * @param string|array  $func      Callable function or class.
 * @param int           $priority  The execution priority.
 * 
 * @return bool
 */
\Shieldon\Event\Event::addLister(string $name, $func, int $priority = 10): bool

/**
 * @param string $name The name of an event.
 * @param array  $args The arguments.
 * 
 * @return mixed
 */
\Shieldon\Event\Event::doDispatch(string $name, array $args = []): mixed

\Shieldon\Event\Event::addListener('test_1', function() {
    echo 'This is a closure function call.';
});

$result = \Shieldon\Event\Event::doDispatch('test_1');

function test_event_disptcher()
{
    echo 'This is a function call.';
}

\Shieldon\Event\Event::addListener('test_2', 'test_event_disptcher');

$result = \Shieldon\Event\Event::doDispatch('test_2');

$example = new Example();

\Shieldon\Event\Event::addListener('test_3', [$example, 'example1']);

$result = \Shieldon\Event\Event::doDispatch('test_3');