3
3
namespace wireframe \ComposerInstaller ;
4
4
5
5
use Composer \Composer ;
6
+ use Composer \EventDispatcher \EventSubscriberInterface ;
6
7
use Composer \IO \IOInterface ;
7
8
use Composer \Plugin \PluginInterface ;
9
+ use Composer \Installer \PackageEvent ;
10
+ use Composer \Installer \PackageEvents ;
8
11
9
12
/**
10
13
* The Plugin class
14
17
* @author Teppo Koivula <[email protected] >
15
18
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
16
19
*/
17
- class Plugin implements PluginInterface
20
+ class Plugin implements PluginInterface, EventSubscriberInterface
18
21
{
19
22
/**
20
23
* Register custom installers for ProcessWire modules and site profiles.
@@ -28,4 +31,38 @@ public function activate(Composer $composer, IOInterface $io)
28
31
$ installationManager ->addInstaller (new ModuleInstaller ($ io , $ composer ));
29
32
$ installationManager ->addInstaller (new SiteProfileInstaller ($ io , $ composer ));
30
33
}
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
+ }
31
68
}
0 commit comments