Skip to content

Commit

Permalink
develop
Browse files Browse the repository at this point in the history
  • Loading branch information
server committed Nov 14, 2021
1 parent 54fbcc2 commit 038c326
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vendor/modstart/modstart/src/ModStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Cache;
use ModStart\Core\Exception\BizException;
use ModStart\Form\Form;
use ModStart\Module\ModuleManager;
use ModStart\Support\Manager\FieldManager;
use ModStart\Support\Manager\WidgetManager;

Expand Down Expand Up @@ -38,6 +39,10 @@ public static function clearCache()
self::safeCleanOptimizedFile('bootstrap/cache/compiled.php');
self::safeCleanOptimizedFile('bootstrap/cache/services.json');
self::safeCleanOptimizedFile('bootstrap/cache/config.php');

if (method_exists(ModuleManager::class, 'hotReloadSystemConfig')) {
ModuleManager::hotReloadSystemConfig();
}
}

private static function safeCleanOptimizedFile($file)
Expand Down
25 changes: 24 additions & 1 deletion vendor/modstart/modstart/src/Module/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ public static function listAllEnabledModules()
* 列出所有模块,包括系统和用户安装
* @return array|mixed
*/
public static function listAllInstalledModules()
public static function listAllInstalledModules($forceReload = false)
{
static $modules = null;
if ($forceReload) {
$modules = null;
}
if (null !== $modules) {
return $modules;
}
Expand Down Expand Up @@ -497,4 +500,24 @@ public static function getModuleConfigKeyValueItem($module, $key, $itemKey, $def
return $default;
}

/**
* 动态重载
*/
public static function hotReloadSystemConfig()
{
$configSystem = config('module.system', []);
$file = base_path('config/module.php');
if (file_exists($file)) {
if (function_exists('opcache_invalidate')) {
opcache_invalidate($file);
}
$configModuleContent = (include $file);
$configSystem = array_merge($configSystem, $configModuleContent['system']);
config([
'module.system' => $configSystem,
]);
}
self::listAllInstalledModules(true);
}

}

0 comments on commit 038c326

Please sign in to comment.