Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 62 lines (54 sloc) 1.094 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php
/**
* Event Handler Class
* @package class
*/
class Event {

private static $instance;

/**
* Events list to fire
*
* @var array
*/
private $event_list = array();

private function __construct() {}
private function __clone() {}

/**
* Add event
*
* @param string $event_name
* @param string $callback
* @return void
*/
public static function add($event_name,$callback) {
$event = self::get_instance();
$event->event_list[$event_name][] = $callback;
}

/**
* Fire a event
*
* @param string $event_name
* @param string $params
* @return void
*/
public static function fire($event_name, $params =null) {
$event = self::get_instance();

if(array_key_exists($event_name,$event->event_list)){
foreach ($event->event_list[$event_name] as $callback) {
call_user_func_array($callback, array(&$params));
}
}
}

/**
* Get singleton instance
*
* @return Event
*/
public static function get_instance() {
if (!isset(self::$instance)) {
     self::$instance = new Event();
}
return self::$instance;
}

}
?>
Something went wrong with that request. Please try again.