15
15
16
16
use Composer \Composer ;
17
17
use Composer \Downloader \DownloaderInterface ;
18
+ use Composer \Factory ;
18
19
use Composer \Installer \PackageEvents ;
19
20
use Composer \IO \IOInterface ;
20
21
use Composer \Plugin \PluginInterface ;
@@ -54,20 +55,46 @@ class Plugin implements PluginInterface, EventSubscriberInterface
54
55
/**
55
56
* Activate the plugin (called from {@see \Composer\Plugin\PluginManager})
56
57
*
57
- * @param \Composer\Composer $composer
58
+ * @param \Composer\Composer $composer
58
59
* @param \Composer\IO\IOInterface $io
59
60
*/
60
61
public function activate (Composer $ composer , IOInterface $ io )
61
62
{
62
63
$ this ->io = $ io ;
63
64
$ this ->composer = $ composer ;
64
- $ this ->downloader = new Downloader \Composer ($ io );
65
+ $ this ->downloader = new Downloader \Composer ($ io, Factory:: createConfig ( $ io ) );
65
66
66
67
// Add the installer
67
68
$ noopInstaller = new Installer ($ io );
68
69
$ composer ->getInstallationManager ()->addInstaller ($ noopInstaller );
69
70
}
70
71
72
+ /**
73
+ * Remove any hooks from Composer
74
+ *
75
+ * This will be called when a plugin is deactivated before being
76
+ * uninstalled, but also before it gets upgraded to a new version
77
+ * so the old one can be deactivated and the new one activated.
78
+ *
79
+ * @param Composer $composer
80
+ * @param IOInterface $io
81
+ */
82
+ public function deactivate (Composer $ composer , IOInterface $ io )
83
+ {
84
+ }
85
+
86
+ /**
87
+ * Prepare the plugin to be uninstalled
88
+ *
89
+ * This will be called after deactivate.
90
+ *
91
+ * @param Composer $composer
92
+ * @param IOInterface $io
93
+ */
94
+ public function uninstall (Composer $ composer , IOInterface $ io )
95
+ {
96
+ }
97
+
71
98
/**
72
99
* Get the events, this {@see \Composer\EventDispatcher\EventSubscriberInterface}
73
100
* subscribes to
@@ -77,17 +104,17 @@ public function activate(Composer $composer, IOInterface $io)
77
104
public static function getSubscribedEvents ()
78
105
{
79
106
return array (
80
- PackageEvents::PRE_PACKAGE_UNINSTALL => array ('restore ' ),
81
- PackageEvents::PRE_PACKAGE_UPDATE => array ('restore ' ),
82
- ScriptEvents::POST_UPDATE_CMD => array ('apply ' ),
83
- ScriptEvents::POST_INSTALL_CMD => array ('apply ' ),
107
+ PackageEvents::PRE_PACKAGE_UNINSTALL => array ('restore ' ),
108
+ PackageEvents::PRE_PACKAGE_UPDATE => array ('restore ' ),
109
+ ScriptEvents::POST_UPDATE_CMD => array ('apply ' ),
110
+ ScriptEvents::POST_INSTALL_CMD => array ('apply ' ),
84
111
);
85
112
}
86
113
87
114
/**
88
115
* Revert patches on/from packages that are going to be removed
89
116
*
90
- * @param PackageEvent $event
117
+ * @param PackageEvent $event
91
118
* @throws Exception
92
119
*
93
120
* @return void
@@ -147,11 +174,11 @@ public function apply(Event $event)
147
174
$ patch ->apply ($ packagePath , true );
148
175
} catch (PatchCommandException $ applyException ) {
149
176
try {
150
- // If this won't fail, patch was already applied
151
- $ patch ->revert ($ packagePath , true );
177
+ // If this won't fail, patch was already applied
178
+ $ patch ->revert ($ packagePath , true );
152
179
} catch (PatchCommandException $ revertException ) {
153
- // Patch seems not to be applied and fails as well
154
- $ this ->writePatchNotice ('apply ' , $ patch , $ package , $ applyException );
180
+ // Patch seems not to be applied and fails as well
181
+ $ this ->writePatchNotice ('apply ' , $ patch , $ package , $ applyException );
155
182
}
156
183
continue ;
157
184
}
@@ -165,8 +192,8 @@ public function apply(Event $event)
165
192
/**
166
193
* Get the patches and packages that are not already in $history
167
194
*
168
- * @param \Composer\Package\PackageInterface $initialPackage
169
- * @param array &$history
195
+ * @param \Composer\Package\PackageInterface $initialPackage
196
+ * @param array &$history
170
197
* @return array
171
198
*/
172
199
protected function getPatches (PackageInterface $ initialPackage , array &$ history )
@@ -204,7 +231,7 @@ protected function getPatches(PackageInterface $initialPackage, array &$history)
204
231
/**
205
232
* Get the install path for a package
206
233
*
207
- * @param \Composer\Package\PackageInterface $package
234
+ * @param \Composer\Package\PackageInterface $package
208
235
* @return string
209
236
*/
210
237
protected function getPackagePath (PackageInterface $ package )
@@ -215,9 +242,9 @@ protected function getPackagePath(PackageInterface $package)
215
242
/**
216
243
* Write a notice to IO
217
244
*
218
- * @param string $action
219
- * @param \Netresearch\Composer\Patches\Patch $patch
220
- * @param \Composer\Package\PackageInterface $package
245
+ * @param string $action
246
+ * @param \Netresearch\Composer\Patches\Patch $patch
247
+ * @param \Composer\Package\PackageInterface $package
221
248
* @param \Netresearch\Composer\Patches\Exception $exception
222
249
*/
223
250
protected function writePatchNotice ($ action , Patch $ patch , PackageInterface $ package , $ exception = null )
0 commit comments