]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - hook.php
Separate Server Bans tab
[irc/unrealircd/unrealircd-webpanel.git] / hook.php
1 <?php
2
3 define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
4
5 /**
6 * Class for "Hook"
7 * This is the main function which gets called whenever you want to use a Hook.
8 *
9 * Example:
10 * Calling the Hook using a function:
11 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
12 *
13 * This Hook references the function 'bob', and will run this
14 * function bob
15 * {
16 * echo "We rehashed!";
17 * }
18 *
19 * Example 2:
20 * Calling the Hook using an initialized object class method:
21 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
22 *
23 * Example 3:
24 * Calling the Hook using a static class method:
25 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
26 *
27 */
28 class Hook {
29
30 /** A static list of Hooks and their associated functions */
31 private static $actions = [];
32
33 /** Runs a Hook.
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.
38 *
39 */
40 public static function run($Hook, &$args = array())
41 {
42 if (!empty(self::$actions[$Hook]))
43 foreach (self::$actions[$Hook] as &$f)
44 $f($args);
45
46 }
47
48 /** Calls a Hook
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.
52 */
53 public static function func($Hook, $function)
54 {
55 self::$actions[$Hook][] = $function;
56 }
57
58 /** Deletes a Hook
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.
62 */
63
64 public static function del($Hook, $function)
65 {
66 for ($i = 0; isset(self::$actions[$Hook][$i]); $i++)
67 if (self::$actions[$Hook][$i] == $function)
68 array_splice(self::$actions[$Hook],$i);
69 }
70 }