| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- declare(strict_types=1);
- namespace SixShop\Core;
- use Composer\Json\JsonFile;
- use Exception;
- use SixShop\Core\Contracts\ExtensionInterface;
- use think\helper\Macroable;
- /**
- * @method bool available() 扩展是否可用
- */
- abstract class ExtensionAbstract implements ExtensionInterface
- {
- use Macroable;
- protected array $info;
- protected bool $isBooted = false;
- /**
- * @throws Exception
- */
- public function getInfo(): array
- {
- if (empty($this->info)) {
- if (file_exists($this->getBaseDir() . '/info.php')) {
- $this->info = require $this->getBaseDir() . '/info.php';
- } else {
- $localConfig = $this->getBaseDir() . '/composer.json';
- $file = new JsonFile($localConfig);
- $localConfig = $file->read();
- $this->info = [
- 'id' => static::EXTENSION_ID,
- 'name' => $localConfig['name'],
- 'description' => $localConfig['description'],
- ];
- }
- }
- return $this->info;
- }
- abstract protected function getBaseDir(): string;
- public function getConfig(): array
- {
- if (!file_exists($this->getBaseDir() . '/config.php')) {
- return [];
- }
- return require $this->getBaseDir() . '/config.php';
- }
- public function install(): void
- {
- }
- public function uninstall(): void
- {
- }
- public function getCommands(): array
- {
- if (!file_exists($this->getBaseDir() . '/command.php')) {
- return [];
- }
- return require $this->getBaseDir() . '/command.php';
- }
- public function getHooks(): array
- {
- return [];
- }
- /**
- * 获取路由
- * @return array<string, string>
- */
- public function getRoutes(): array
- {
- $adminRoute = $this->getBaseDir() . '/route/admin.php';
- $apiRoute = $this->getBaseDir() . '/route/api.php';
- $routes = [];
- if (file_exists($adminRoute)) {
- $routes['admin'] = $adminRoute;
- }
- if (file_exists($apiRoute)) {
- $routes['api'] = $apiRoute;
- }
- return $routes;
- }
- public function getCronJobs(): array
- {
- return [];
- }
- public function boot(): void
- {
- $this->isBooted = true;
- }
- }
|