| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- declare(strict_types=1);
- namespace SixShop\System;
- use SixShop\Core\ExtensionAbstract;
- use SixShop\Core\Service\AutoloadService;
- use SixShop\System\Cron\SystemCron;
- use SixShop\System\Enum\ExtensionStatusEnum;
- use SixShop\System\Hook\ExtensionStatusHook;
- use SixShop\System\Hook\GatheringCrontabEventHook;
- use think\db\exception\PDOException;
- use function SixShop\Core\extension_name_list;
- class Extension extends ExtensionAbstract
- {
- public function __construct(private readonly AutoloadService $autoloadService)
- {
- }
- public function getHooks(): array
- {
- return [
- ExtensionStatusHook::class,
- GatheringCrontabEventHook::class
- ];
- }
- public function getCronJobs(): array
- {
- return [
- SystemCron::class
- ];
- }
- public function boot(): void
- {
- if ($this->isBooted) {
- return;
- }
- foreach (extension_name_list() as $extensionID) {
- /** @var ExtensionAbstract $extension */
- $extension = $this->autoloadService->getExtension($extensionID);
- $className = get_class($extension);
- if (method_exists($extension, 'available')
- || $className::hasMacro('available')
- ) {
- continue;
- }
- $className::macro('available', function () {
- $extensionID = $this->getInfo()['id'];
- try {
- $info = app()->make(ExtensionManager::class)->getInfo($extensionID);
- } catch (PDOException) {
- // 新装系统的时候system扩展还未安装
- return false;
- }
- return $info->status === ExtensionStatusEnum::ENABLED;
- });
- }
- parent::boot();
- }
- public function available()
- {
- return true;
- }
- protected function getBaseDir(): string
- {
- return dirname(__DIR__);
- }
- }
|