33namespace wireframe \ComposerInstaller ;
44
55use Composer \Composer ;
6+ use Composer \EventDispatcher \EventSubscriberInterface ;
67use Composer \IO \IOInterface ;
78use Composer \Plugin \PluginInterface ;
9+ use Composer \Installer \PackageEvent ;
10+ use Composer \Installer \PackageEvents ;
811
912/**
1013 * The Plugin class
1417 * @author Teppo Koivula <teppo@wireframe-framework.com>
1518 * @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
1619 */
17- class Plugin implements PluginInterface
20+ class Plugin implements PluginInterface, EventSubscriberInterface
1821{
1922 /**
2023 * Register custom installers for ProcessWire modules and site profiles.
@@ -28,4 +31,38 @@ public function activate(Composer $composer, IOInterface $io)
2831 $ installationManager ->addInstaller (new ModuleInstaller ($ io , $ composer ));
2932 $ installationManager ->addInstaller (new SiteProfileInstaller ($ io , $ composer ));
3033 }
34+
35+ /**
36+ * Register pre package install event listener
37+ *
38+ * @return array
39+ */
40+ public static function getSubscribedEvents ()
41+ {
42+ return [
43+ PackageEvents::PRE_PACKAGE_INSTALL => [
44+ array ('prePackageInstall ' , 0 )
45+ ],
46+ ];
47+ }
48+
49+ /**
50+ * Pre package install event listener
51+ *
52+ * wireframe-framework/processwire-composer-installer and hari/pw-module are not fully compatible,
53+ * which means that when wireframe-framework/processwire-composer-installer is enabled, we need to
54+ * disable the hari/pw-module SystemInstaller composer-installer.
55+ *
56+ * @param PackageEvent $event
57+ */
58+ public static function prePackageInstall (PackageEvent $ event )
59+ {
60+ $ package = $ event ->getOperation ()->getPackage ();
61+ if ($ package ->getType () !== 'pw-module ' ) return ;
62+ $ installationManager = $ event ->getComposer ()->getInstallationManager ();
63+ $ moduleInstaller = $ installationManager ->getInstaller ('pw-module ' );
64+ if (strpos (get_class ($ moduleInstaller ), 'PW\Composer\SystemInstaller ' ) === 0 ) {
65+ $ installationManager ->removeInstaller ($ moduleInstaller );
66+ }
67+ }
3168}
0 commit comments