123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- defined('GNUSOCIAL') || die();
- class Event {
-
- protected static $_handlers = array();
-
- public static function addHandler($name, $handler) {
- if (array_key_exists($name, Event::$_handlers)) {
- Event::$_handlers[$name][] = $handler;
- } else {
- Event::$_handlers[$name] = array($handler);
- }
- }
-
- public static function handle($name, array $args = []) {
- $result = null;
- if (array_key_exists($name, Event::$_handlers)) {
- foreach (Event::$_handlers[$name] as $handler) {
- $result = call_user_func_array($handler, $args);
- if ($result === false) {
- break;
- }
- }
- }
- return ($result !== false);
- }
-
- public static function hasHandler($name, $plugin=null) {
- if (array_key_exists($name, Event::$_handlers)) {
- if (isset($plugin)) {
- foreach (Event::$_handlers[$name] as $handler) {
- if (get_class($handler[0]) == $plugin) {
- return true;
- }
- }
- } else {
- return true;
- }
- }
- return false;
- }
- public static function getHandlers($name)
- {
- return Event::$_handlers[$name];
- }
-
- public static function clearHandlers() {
- Event::$_handlers = array();
- }
- }
|