1 | <?php |
||
45 | class Hook extends BaseObject |
||
46 | { |
||
47 | private static $_hooks = []; |
||
48 | |||
49 | /** |
||
50 | * Register a hook listener. |
||
51 | * |
||
52 | * Define the name of the type of listener. |
||
53 | * |
||
54 | * @param string $name The name of the hook. |
||
55 | * @param callable|array $value An array with `[$object, 'method']` or a callable function `function($hook) {}`. |
||
56 | * @param boolean $prepend Whether to prepend the item to the start or as by default to the end of the stack. |
||
57 | */ |
||
58 | public static function on($name, $value, $prepend = false) |
||
68 | |||
69 | /** |
||
70 | * Trigger the hooks and returns the {{luya\base\HookEvent}} objects. |
||
71 | * |
||
72 | * @param string $name The hook name. |
||
73 | * @return array An array with {{luya\base\HookEvent}} objects. |
||
74 | * @throws Exception |
||
75 | */ |
||
76 | protected static function trigger($name) |
||
106 | |||
107 | /** |
||
108 | * Get the string output of the hooks. |
||
109 | * |
||
110 | * @param string $name The name of the hook to trigger. |
||
111 | * @return string |
||
112 | */ |
||
113 | public static function string($name) |
||
122 | |||
123 | /** |
||
124 | * Get the array output of iteration hooks. |
||
125 | * |
||
126 | * @param string $name The name of the hook to trigger. |
||
127 | * @return array |
||
128 | */ |
||
129 | public static function iterate($name) |
||
138 | } |
||
139 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: