app->bind(Handle::class, ExceptionHandle::class); $this->app->bind('think\Request', Request::class); $this->app->bind('classLoader', require $this->app->getRootPath() . 'vendor/autoload.php'); self::$extensionPath = $this->app->getRootPath() . 'extension' . DIRECTORY_SEPARATOR; $this->initExtensionList(); } public function boot(): void { $this->app->make(AutoloadService::class)->init($this->app); $this->app->make(HookAttributeService::class)->init($this->app); $this->app->event->listen(HttpRun::class,function (){ $this->registerRoutes($this->app->make(RegisterRouteService::class)->init($this->app)); }); /*$this->app->make(CommandService::class)->init(function ($commands){ $this->commands($commands); });*/ } public function initExtensionList(): void { if (empty(self::$extensionNameList)) { $coreFile = $this->app->getRootPath() . 'runtime/module_name_list_core.php'; if (file_exists($coreFile)) { self::$extensionNameList = require $coreFile; } else { $extensionInfoList = []; $extensionDirs = array_diff(scandir(self::extensionPath), ['.', '..']); foreach ($extensionDirs as $item) { if (!is_dir(self::extensionPath . $item)) { continue; } $infoFile = self::extensionPath . $item . '/info.php'; if (is_file($infoFile)) { $info = require $infoFile; $info['weight'] = $info['weight'] ?? 10000; if ($info['is_core'] ?? false) { self::$extensionNameList[] = $info['id']; $extensionInfoList[] = $info; } } } usort($extensionInfoList, function ($a, $b) { return $a['weight'] <=> $b['weight']; }); $header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL; $content = 'app->getRootPath() . 'runtime/module_name_list_normal.php'; if (file_exists($normalFile)) { self::$extensionNameList = array_merge(self::$extensionNameList, require $normalFile); } } } public function loadEnv(string $envName = ''): void { $home = getenv('HOME'); $envFile = $envName ? $home . '/.env.' . $envName : $home . '/.env'; if (is_file($envFile)) { $this->app->env->load($envFile); return; } $this->app->loadEnv($envName); } }