Prechádzať zdrojové kódy

refactor(core): 重构插件安装逻辑

- 将 ExtensionInstaller 类中的事件处理逻辑移至新的 Plugin 类
- 更新 composer.json 中的类配置,指向新的 Plugin 类
- 删除 ExtensionInstaller 类中不再使用的 EventSubscriberInterface 接口
runphp 7 mesiacov pred
rodič
commit
edc8f16443
3 zmenil súbory, kde vykonal 50 pridanie a 19 odobranie
  1. 1 1
      composer.json
  2. 1 18
      src/ExtensionInstaller.php
  3. 48 0
      src/Plugin.php

+ 1 - 1
composer.json

@@ -30,6 +30,6 @@
                 "SixShop\\Core\\Service\\CoreService"
             ]
         },
-        "class": "SixShop\\Core\\ExtensionInstaller"
+        "class": "SixShop\\Core\\Plugin"
     }
 }

+ 1 - 18
src/ExtensionInstaller.php

@@ -1,14 +1,11 @@
 <?php
 declare(strict_types=1);
-
 namespace SixShop\Core;
 
-use Composer\EventDispatcher\EventSubscriberInterface;
 use Composer\Installer\LibraryInstaller;
-use Composer\Installer\PackageEvents;
 use Composer\Package\PackageInterface;
 
-class ExtensionInstaller extends LibraryInstaller implements EventSubscriberInterface
+class ExtensionInstaller extends LibraryInstaller
 {
     public function supports(string $packageType)
     {
@@ -19,18 +16,4 @@ class ExtensionInstaller extends LibraryInstaller implements EventSubscriberInte
     {
         return 'extension/' . $package->getPrettyName();
     }
-
-
-    public static function getSubscribedEvents()
-    {
-        return [
-            PackageEvents::POST_PACKAGE_INSTALL => 'onPostPackageInstall',
-        ];
-    }
-
-    public function onPostPackageInstall(PackageEvent $event)
-    {
-        $package = $event->getOperation()->getPackage();
-        $this->io->write('Installing sixshop extension ' . $package->getPrettyName());
-    }
 }

+ 48 - 0
src/Plugin.php

@@ -0,0 +1,48 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Core;
+
+use Composer\Composer;
+use Composer\EventDispatcher\EventSubscriberInterface;
+use Composer\Installer\LibraryInstaller;
+use Composer\Installer\PackageEvent;
+use Composer\Installer\PackageEvents;
+use Composer\IO\IOInterface;
+use Composer\Package\PackageInterface;
+use Composer\Plugin\PluginInterface;
+
+class Plugin implements PluginInterface, EventSubscriberInterface
+{
+
+
+    public function activate(Composer $composer, IOInterface $io)
+    {
+        $installer = new ExtensionInstaller($io, $composer, 'sixshop-extension');
+        $composer->getInstallationManager()->addInstaller($installer);
+    }
+
+
+    public static function getSubscribedEvents()
+    {
+        return [
+            PackageEvents::POST_PACKAGE_INSTALL => 'onPostPackageInstall',
+        ];
+    }
+
+    public function onPostPackageInstall(PackageEvent $event, IOInterface $io)
+    {
+        $package = $event->getOperation()->getPackage();
+        $io->write('Installing sixshop extension ' . $package->getPrettyName());
+    }
+
+    public function deactivate(Composer $composer, IOInterface $io)
+    {
+        // TODO: Implement deactivate() method.
+    }
+
+    public function uninstall(Composer $composer, IOInterface $io)
+    {
+        // TODO: Implement uninstall() method.
+    }
+}