HookLogic.php
2.0 KB
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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\admin\logic;
use think\Db;
class HookLogic
{
/**
* 导入应用钩子
* @param $app
* @return array
* @throws \ReflectionException
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function importHooks($app)
{
$hookConfigFile = cmf_get_app_config_file($app, 'hooks');
if (file_exists($hookConfigFile)) {
$hooksInFile = include $hookConfigFile;
if (empty($hooksInFile) || !is_array($hooksInFile)) {
return;
}
foreach ($hooksInFile as $hookName => $hook) {
$hook['type'] = empty($hook['type']) ? 2 : $hook['type'];
if (!in_array($hook['type'], [2, 3, 4]) && !in_array($app, ['cmf', 'swoole'])) {
$hook['type'] = 2;
}
$findHook = Db::name('hook')->where('hook', $hookName)->count();
$hook['app'] = $app;
if ($findHook > 0) {
Db::name('hook')->where('hook', $hookName)->strict(false)->field(true)->update($hook);
} else {
$hook['hook'] = $hookName;
Db::name('hook')->insert($hook);
}
}
}
}
}