Skip to content

Commit 267c5df

Browse files
committed
Introduce \Icinga\Application\Hook\Essentials
1 parent a73cd1c commit 267c5df

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
abstract protected static function getHookName(): string;
17+
18+
/**
19+
* Return all instances of the hook
20+
*
21+
* @return static[]
22+
*/
23+
public static function all(): array
24+
{
25+
return Hook::all(static::getHookName());
26+
}
27+
28+
/**
29+
* Register a hook provider
30+
*
31+
* @param bool $alwaysRun Whether to always run the hook, without permission check
32+
*/
33+
public static function register(bool $alwaysRun = false): void
34+
{
35+
Hook::register(static::getHookName(), static::class, static::class, $alwaysRun);
36+
}
37+
}

0 commit comments

Comments
 (0)