-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHook.php
More file actions
39 lines (34 loc) · 732 Bytes
/
Hook.php
File metadata and controls
39 lines (34 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace core;
class Hook
{
private static $hooks = [];
public static function add($name)
{
if (isset(self::$hooks[$name])) {
die("DevErr: hook[$name] already added");
}
self::$hooks[$name] = [];
}
public static function listen($name, $file)
{
if (isset(self::$hooks[$name][$file])) {
die("DevErr: hook[$name][$file] already added");
}
self::$hooks[$name][$file] = true;
}
public static function trigger($name, array $args)
{
if (! isset(self::$hooks[$name])) {
error_log(sprintf("Hook(%s) dropped, no listeners", $name));
return;
}
$args["_hook"] = $name;
foreach (self::$hooks[$name] as $fn => $meta) {
$tok = require $fn;
if ($tok === "STOP") {
break;
}
}
}
}