File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
library/Icinga/Application/Hook Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /* Icinga Web 2 | (c) 2026 Icinga GmbH | GPLv2+ */
3+
4+ namespace Icinga \Application \Hook ;
5+
6+ use Icinga \Application \Hook ;
7+
8+ /**
9+ * All hooks are provided and consumed - this trait provides the mechanism
10+ */
11+ trait Essentials
12+ {
13+ /**
14+ * Get the name for {@link Hook::register} and {@link Hook::all}
15+ *
16+ * Legacy hooks must override this and return the name they used to pass to {@link Hook::all},
17+ * new ones should keep this name as-is, but not rely on its current default.
18+ */
19+ protected static function getHookName (): string
20+ {
21+ return self ::class;
22+ }
23+
24+ /**
25+ * Return all instances of the hook
26+ *
27+ * @return static[]
28+ */
29+ public static function all (): array
30+ {
31+ return Hook::all (static ::getHookName ());
32+ }
33+
34+ /**
35+ * Register a hook provider
36+ *
37+ * @param bool $alwaysRun Whether to always run the hook, without permission check
38+ */
39+ public static function register (bool $ alwaysRun = false ): void
40+ {
41+ Hook::register (static ::getHookName (), static ::class, static ::class, $ alwaysRun );
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments