Skip to content

Commit 28b18ff

Browse files
committed
Introduce \Icinga\Application\Hook\Essentials
1 parent a73cd1c commit 28b18ff

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)