Skip to content

A simple, lightweight, intuitive, chainable event handling interface

License

Notifications You must be signed in to change notification settings

PHPPowertools/Event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Component

PHPPowertools is a web application framework for PHP >= 5.4.

PHPPowertools/Event is the third component of the PHPPowertools that has been released to the public.

The purpose of this component is to provide a PHP-based event handling interface similar to both NodeJS's EventEmitter and your browser's EventTarget.

Example use :
use \PowerTools\Event_Emitter as Event_Emitter;

// Define some event handlers
$eventHandlers = [
    'handler1' => function($a = '', $b = '') {
        //   var_dump($this);
        echo 'handler1 fired with parameters "' . $a . '" and "' . $b . '"<br />';
    }, 'handler2' => function($a = '', $b = '') {
        //   var_dump($this);
        echo 'handler2 fired with parameters "' . $a . '" and "' . $b . '"<br />';
    }, 'handler3' => function($a = '', $b = '') {
        //   var_dump($this);
        echo 'handler3 fired with parameters "' . $a . '" and "' . $b . '"<br />';
    }, 'handler4' => function($a = '', $b = '') {
        //   var_dump($this);
        echo 'handler4 fired with parameters "' . $a . '" and "' . $b . '"<br />';
    }
];

// Create an instance of the Event_Emitter class
$emitter = Event_Emitter::factory();

// Add your event handlers to your Event_Emitter instance for the 'go' event.
$emitter->addListeners('go', $eventHandlers);

// Emit the 'go' event, with parameters 'FOO' and 1.
$emitter->emit('go', 'FOO', 1);

// Remove the second event handler for the 'go' event
$emitter->removeListener('go', $eventHandlers['handler2']);

// Remove ALL listeners for the 'go' event
$emitter->removeAllListeners('go');

Supported methods :

  1. These methods have no equivalent in either NodeJS's EventEmitter or your browser's EventTarget.

Author
twitter/johnslegers
John slegers

About

A simple, lightweight, intuitive, chainable event handling interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages