-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.php
79 lines (69 loc) · 1.82 KB
/
Config.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Yonna\Event;
use Exception;
use Yonna\Foundation\System;
class Config
{
protected static $stack = array();
/**
* @return array
*/
public static function fetch(): array
{
return static::$stack;
}
/**
* @param $key
* @param null $default
* @return array|bool|false|string|null
*/
public static function env($key, $default = null)
{
return System::env($key, $default);
}
/**
* 注册触发器,设定需要的参数要求
* @param string $eventClass
* @param array $listenerClasses
* @throws Exception
*/
public static function reg(string $eventClass, array $listenerClasses)
{
if (empty($eventClass)) throw new Exception('not event');
if (empty($listenerClasses)) throw new Exception('not listener');
if (!empty(self::$stack[$eventClass])) {
throw new Exception("Event {$eventClass} already exist");
}
self::$stack[$eventClass] = $listenerClasses;
}
/**
* 删除触发器
* @param string $eventClass
* @throws Exception
*/
public static function del(string $eventClass)
{
if (empty($eventClass)) throw new Exception('not event');
if (isset(self::$stack[$eventClass])) {
unset(self::$stack[$eventClass]);
}
}
/**
* 触发触发器
* @param string $eventClass
* @param $params
* @throws Exception
*/
public static function act(string $eventClass, $params)
{
if (empty($eventClass)) throw new Exception('not event');
if (empty(self::$stack[$eventClass])) {
return;
}
/**
* @var Event $event
*/
$event = new $eventClass($params);
$event->listener(self::$stack[$eventClass]);
}
}