项目初始化
This commit is contained in:
34
app/common/service/moduleService.php
Normal file
34
app/common/service/moduleService.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Service;
|
||||
use think\facade\Event;
|
||||
use app\admin\library\module\Server;
|
||||
|
||||
class moduleService extends Service
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->moduleAppInit();
|
||||
}
|
||||
|
||||
public function moduleAppInit(): void
|
||||
{
|
||||
$installed = Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR);
|
||||
foreach ($installed as $item) {
|
||||
if ($item['state'] != 1) {
|
||||
continue;
|
||||
}
|
||||
$moduleClass = Server::getClass($item['uid']);
|
||||
if (class_exists($moduleClass)) {
|
||||
if (method_exists($moduleClass, 'AppInit')) {
|
||||
Event::listen('AppInit', function () use ($moduleClass) {
|
||||
$handle = new $moduleClass();
|
||||
$handle->AppInit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user