]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-hook.php
3 define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
4 define('HOOKTYPE_PRE_HEADER', 101); /* The hook for pre-header */
8 * This is the main function which gets called whenever you want to use a Hook.
11 * Calling the Hook using a function:
12 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
14 * This Hook references the function 'bob', and will run this
17 * echo "We rehashed!";
21 * Calling the Hook using an initialized object class method:
22 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
25 * Calling the Hook using a static class method:
26 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
31 /** A static list of Hooks and their associated functions */
32 private static $actions = [];
35 * The parameter for $Hook should be a "HOOKTYPE_" as defined in hook.php
36 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
37 * @param array &$args The array of information you are sending along in the Hook, so that other functions may see and modify things.
38 * @return void Does not return anything.
41 public static function run($Hook, &$args = array())
43 if (!empty(self
::$actions[$Hook]))
44 foreach (self
::$actions[$Hook] as &$f)
50 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
51 * @param string|Closure $function This is a string reference to a Closure function or a class method.
52 * @return void Does not return anything.
54 public static function func($Hook, $function)
56 self
::$actions[$Hook][] = $function;
60 * @param string $Hook The Hook from which we are removing a function reference.
61 * @param string $function The name of the function that we are removing.
62 * @return void Does not reuturn anything.
65 public static function del($Hook, $function)
67 for ($i = 0; isset(self
::$actions[$Hook][$i]); $i++
)
68 if (self
::$actions[$Hook][$i] == $function)
69 array_splice(self
::$actions[$Hook],$i);