|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace suda\application; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* 系统事件 |
|
8
|
|
|
*/ |
|
9
|
|
|
class EventRunner |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* 可执行器 |
|
13
|
|
|
* |
|
14
|
|
|
* @var callback |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $runnable; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* 初始化 |
|
20
|
|
|
* |
|
21
|
|
|
* @param callback $runnable |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct($runnable) { |
|
24
|
|
|
$this->runnable = $runnable; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function call(array &$args) |
|
28
|
|
|
{ |
|
29
|
|
|
if (conf('hook.enable', true) == false) { |
|
30
|
|
|
debug()->warning(__('hook.enable == false refuse run command')); |
|
|
|
|
|
|
31
|
|
|
return null; |
|
32
|
|
|
} |
|
33
|
|
|
if (is_string($command)) { |
|
|
|
|
|
|
34
|
|
|
if (preg_match('/^(debug)|d\=/', $command)) { |
|
35
|
|
|
if (conf('debug')) { |
|
|
|
|
|
|
36
|
|
|
return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
} elseif (preg_match('/^(normal)|n\=/', $command)) { |
|
39
|
|
|
if (conf('debug') == false) { |
|
40
|
|
|
return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args); |
|
41
|
|
|
} |
|
42
|
|
|
} elseif (preg_match('/^is?\:(.+?)\=/', $command, $matchs)) { |
|
43
|
|
|
$module = $matchs[1]; |
|
44
|
|
|
if (app()->getActiveModule() == app()->getModuleFullName($module)) { |
|
|
|
|
|
|
45
|
|
|
return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args); |
|
46
|
|
|
} |
|
47
|
|
|
} elseif (preg_match('/^(?:reachable)|r\:(.+?)\=/', $command, $matchs)) { |
|
48
|
|
|
$module = $matchs[1]; |
|
49
|
|
|
if (app()->isModuleReachable($module)) { |
|
50
|
|
|
return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args); |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
return (new Command($command))->exec($args); |
|
54
|
|
|
} |
|
55
|
|
|
} else { |
|
56
|
|
|
return (new Command($command))->exec($args); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|