完善扩展插件机制

This commit is contained in:
2020-04-13 10:40:47 +08:00
parent 6560f723cd
commit 53ccc5f123
11 changed files with 167 additions and 142 deletions

View File

@@ -15,6 +15,7 @@ use think\facade\Cache;
use think\Validate;
use app\model\Config;
use think\facade\Route;
use think\facade\Event;
use app\model\Hooks;
class Base {
@@ -72,11 +73,26 @@ class Base {
$config = Config::getConfigList($this->request);
Cache::set('system_config_data', $config);
}
$hooks = Hooks::where('status', 1)->column('addons', 'name');
foreach($hooks as $key => $value){
$hooks[$key] = $value ? explode(",", $value) : [];
$hooks = Cache::get('sentcms_hooks');
if (!$hooks) {
$hooks = Hooks::where('status', 1)->column('addons', 'name');
foreach($hooks as $key => $values){
if (is_string($values)) {
$values = explode(',', $values);
} else {
$values = (array) $values;
}
$hooks[$key] = array_filter(array_map(function ($v) use ($key) {
return [get_addons_class($v), $key];
}, $values));
// $hooks[$key] = $value ? explode(",", $value) : [];
}
}
Cache::set('sentcms_hooks', $hooks);
if (!empty($hooks)) {
Cache::set('sentcms_hooks', $hooks);
Event::listenEvents($hooks);
}
View::assign('config', $config);
// 控制器初始化
$this->initialize();