Forráskód Böngészése

chore: 去掉废弃的代码

runphp 1 hónapja
szülő
commit
e7514a2f8b
4 módosított fájl, 14 hozzáadás és 56 törlés
  1. 3 2
      composer.json
  2. 1 21
      src/Service/AutoloadService.php
  3. 9 32
      src/Service/CoreService.php
  4. 1 1
      src/functions.php

+ 3 - 2
composer.json

@@ -22,6 +22,8 @@
   "require": {
     "php": ">=8.3",
     "composer/composer": "^2.9.2",
+    "mnsami/composer-custom-directory-installer": "^2.2",
+    "opis/closure": "^4.3.1",
     "polyfills/array-first-array-last": "^1.0.1",
     "topthink/framework": "^8.1",
     "topthink/think-orm": "^4.0",
@@ -29,8 +31,7 @@
     "topthink/think-multi-app": "^1.1.1",
     "topthink/think-queue": "^3.0.12",
     "topthink/think-view": "^2.0.5",
-    "topthink/think-cors": "^1.0.2",
-    "opis/closure": "^4.3.1"
+    "topthink/think-cors": "^1.0.2"
   },
   "extra": {
     "think": {

+ 1 - 21
src/Service/AutoloadService.php

@@ -7,15 +7,13 @@ namespace SixShop\Core\Service;
 use SixShop\Core\Contracts\ExtensionInterface;
 use think\App;
 
-use function SixShop\Core\extension_path;
-
 readonly class AutoloadService
 {
     public function __construct(private App $app)
     {
     }
 
-    public function load(array $extensionComposerMap, array $extensionNameList): array
+    public function load(array $extensionComposerMap): array
     {
         $invalidExtensionIDs = [];
         foreach ($extensionComposerMap as $extensionID => $composerFile) {
@@ -25,24 +23,6 @@ readonly class AutoloadService
             }
             $this->app->bind('extension.' . $extensionID, $composerFile['extra']['sixshop']['class']);
         }
-        $extensionPath = extension_path();
-        $classLoader = $this->app->get('classLoader');
-        foreach ($extensionNameList as $moduleName) {
-            $dir = $extensionPath . $moduleName;
-            if (!file_exists($dir . '/composer.json')) {
-                $namespace = "SixShop\\Extension\\$moduleName\\";
-                $path = $dir . '/src';
-                if (!isset($classLoader->getPrefixesPsr4()[$namespace])) {
-                    $classLoader->addPsr4($namespace, $path);
-                    $helperFunctionFile = $dir . "/src/helper.php";
-                    if (is_file($helperFunctionFile)) {
-                        require_once $helperFunctionFile;
-                    }
-                }
-                $extensionClass = $namespace . 'Extension';
-                $this->app->bind('extension.' . $moduleName, $extensionClass);
-            }
-        }
         return $invalidExtensionIDs;
     }
 

+ 9 - 32
src/Service/CoreService.php

@@ -16,8 +16,6 @@ use think\event\HttpRun;
 use think\exception\Handle;
 use think\Service;
 
-use function SixShop\Core\extension_path;
-
 class CoreService extends Service
 {
     public static string $extensionPath;
@@ -27,16 +25,18 @@ class CoreService extends Service
      */
     public static array $extensionComposerMap = [];
 
-    /* @deprecated */
-    public static array $extensionNameList = [];
-
-    private static array $normalExtensionNameList = [];
+    private static array $invalidExtensionIDs = [];
 
     public static function getExtensionComposerMap(): array
     {
         return self::$extensionComposerMap;
     }
 
+    public static function getExtensionNameList(): array
+    {
+        return array_diff(array_keys(self::$extensionComposerMap), self::$invalidExtensionIDs);
+    }
+
     /**
      * @throws ParsingException
      */
@@ -50,7 +50,6 @@ class CoreService extends Service
         );
         self::$extensionPath = $this->app->getRootPath() . 'extension' . DIRECTORY_SEPARATOR;
         $this->initExtensionList();
-        $this->compatibleExtensionNameList();
     }
 
     /**
@@ -86,38 +85,16 @@ class CoreService extends Service
         file_put_contents($extensionComposerFile, $content);
     }
 
-    /* @deprecated */
-    private function compatibleExtensionNameList(): void
-    {
-        if (empty(self::$extensionNameList)) {
-            self::$extensionNameList = array_keys(self::$extensionComposerMap);
-            $normalFile = $this->app->getRootPath() . 'runtime/module_name_list_normal.php';
-            if (file_exists($normalFile)) {
-                $normalExtensionList = require $normalFile;
-                foreach ($normalExtensionList as $item) {
-                    if (array_key_exists($item, self::$extensionComposerMap)) {
-                        continue;
-                    }
-                    if (is_dir(extension_path($item) . 'src')) {
-                        self::$extensionNameList[] = $item;
-                        self::$normalExtensionNameList[] = $item;
-                    }
-                }
-            }
-        }
-    }
-
     /**
      * @throws ReflectionException
      */
     public function boot(): void
     {
         $autoloadService = $this->app->make(AutoloadService::class);
-        $invalidExtensionIDs = $autoloadService->load(self::$extensionComposerMap, self::$normalExtensionNameList);
-        self::$extensionNameList = array_diff(self::$extensionNameList, $invalidExtensionIDs);
+        self::$invalidExtensionIDs = $autoloadService->load(self::$extensionComposerMap);
         $this->app->get('extension.system')->boot();
-        foreach (self::$extensionComposerMap + self::$normalExtensionNameList as $moduleName => $_) {
-            if (in_array($moduleName, $invalidExtensionIDs)) {
+        foreach (self::$extensionComposerMap as $moduleName => $_) {
+            if (in_array($moduleName, self::$invalidExtensionIDs)) {
                 continue;
             }
             $extension = $autoloadService->getExtension($moduleName);

+ 1 - 1
src/functions.php

@@ -176,7 +176,7 @@ function extension_path(string $extensionID = ''): string
  */
 function extension_name_list(): array
 {
-    return CoreService::$extensionNameList;
+    return CoreService::getExtensionNameList();
 }