]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - hook.php
3 define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
7 * This is the main function which gets called whenever you want to use a Hook.
10 * Calling the Hook using a function:
11 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
13 * This Hook references the function 'bob', and will run this
16 * echo "We rehashed!";
20 * Calling the Hook using an initialized object class method:
21 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
24 * Calling the Hook using a static class method:
25 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
30 /** A static list of Hooks and their associated functions */
31 private static $actions = [];
34 * The parameter for $Hook should be a "HOOKTYPE_" as defined in hook.php
35 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
36 * @param array &$args The array of information you are sending along in the Hook, so that other functions may see and modify things.
37 * @return void Does not return anything.
40 public static function run($Hook, &$args = array())
42 if (!empty(self
::$actions[$Hook]))
43 foreach (self
::$actions[$Hook] as &$f)
49 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
50 * @param string|Closure $function This is a string reference to a Closure function or a class method.
51 * @return void Does not return anything.
53 public static function func($Hook, $function)
55 self
::$actions[$Hook][] = $function;
59 * @param string $Hook The Hook from which we are removing a function reference.
60 * @param string $function The name of the function that we are removing.
61 * @return void Does not reuturn anything.
64 public static function del($Hook, $function)
66 for ($i = 0; isset(self
::$actions[$Hook][$i]); $i++
)
67 if (self
::$actions[$Hook][$i] == $function)
68 array_splice(self
::$actions[$Hook],$i);