PHP Classes

PHP Event Aggregator: Manager and listener of registered events

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 152 All time: 9,062 This week: 660Up
Version License PHP version Categories
event-aggregator 1GNU General Publi...5PHP 5, Language, Design Patterns
Description 

Author

This class is a manager and listener of registered events.

It can register events with a given name and a callback function to call when the events are triggered.

The class can also trigger events when a function of the class is called with the name of a given registered event.

An optional priority parameter may be passed to specify the order by which multiple event handler functions should be called.

Picture of Kiril Savchev
  Performance   Level  
Name: Kiril Savchev <contact>
Classes: 6 packages by
Country: Bulgaria Bulgaria
Age: 38
All time rank: 266618 in Bulgaria Bulgaria
Week rank: 280 Up1 in Bulgaria Bulgaria Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

require_once 'EventAggregator.php';

/**
 * Use this class to attach methods to events
 *
 */
class TestClass {
    static function
test() { var_dump(__CLASS__); }
    static function
test2($a,$b,$c='a') {
       
var_dump($a,$b,$c);
        echo
$GLOBALS['Event']->getCurrentEvent();
    }
}

// Instantiate the event aggregator:
$Event = EventAggregator::getInstance();

// Attach some callbacks to custom event 'testEvent':
$Event->on('testEvent',array('TestClass','test'));
$Event->on('testEvent',array('TestClass','test2'),2);

// Call the event:
$Event->testEvent(__FILE__,__LINE__,true);

// These commented lines do the same as the above - fires the event 'testEvent' with params __FILE__, __LINE__ and true
// $Event->trigger('testEvent',array(__FILE__,__LINE__,true));
// $Event->fire('testEvent',__FILE__,__LINE__,true);

?>


  Files folder image Files  
File Role Description
Plain text file EventAggregator.php Class Class file
Accessible without login Plain text file test.php Example Test examples

 Version Control Unique User Downloads Download Rankings  
 0%
Total:152
This week:0
All time:9,062
This week:660Up