Skip to content

Commit b11a27d

Browse files
committed
Add RequestHook
Add a hook that hooks into different states of a request. The implementation starts with hooking into after non xhr requests are dispatched. This is meant to be extended for more more states like before a request gets dispatched.
1 parent 326616c commit b11a27d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Icinga\Application\Hook;
4+
5+
use Icinga\Application\Hook;
6+
use Icinga\Web\Request;
7+
8+
abstract class RequestHook extends Hook
9+
{
10+
/**
11+
* Triggered after a request has been dispatched
12+
*
13+
* @param Request $request
14+
*
15+
* @return void
16+
*/
17+
abstract public function onPostDispatch(Request $request): void;
18+
19+
/**
20+
* Call the onPostDispatch() method of all registered RequestHooks
21+
*
22+
* @param Request $request
23+
*/
24+
final public static function postDispatch(Request $request): void
25+
{
26+
array_map(
27+
fn($hook) => $hook->onPostDispatch($request),
28+
static::all('Request')
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)