1 | <?php namespace Arcanedev\Composer; |
||
30 | class ComposerPlugin implements PluginInterface, EventSubscriberInterface |
||
31 | { |
||
32 | /* ------------------------------------------------------------------------------------------------ |
||
33 | | Constants |
||
34 | | ------------------------------------------------------------------------------------------------ |
||
35 | */ |
||
36 | /** |
||
37 | * Package name |
||
38 | */ |
||
39 | const PACKAGE_NAME = 'arcanedev/composer'; |
||
40 | |||
41 | /** |
||
42 | * Name of the composer 1.1 init event. |
||
43 | */ |
||
44 | const COMPAT_PLUGINEVENTS_INIT = 'init'; |
||
45 | |||
46 | /** |
||
47 | * Plugin key |
||
48 | */ |
||
49 | const PLUGIN_KEY = 'merge-plugin'; |
||
50 | |||
51 | /* ------------------------------------------------------------------------------------------------ |
||
52 | | Properties |
||
53 | | ------------------------------------------------------------------------------------------------ |
||
54 | */ |
||
55 | /** @var \Composer\Composer */ |
||
56 | protected $composer; |
||
57 | |||
58 | /** @var \Arcanedev\Composer\Entities\PluginState */ |
||
59 | protected $state; |
||
60 | |||
61 | /** @var \Arcanedev\Composer\Utilities\Logger */ |
||
62 | protected $logger; |
||
63 | |||
64 | /** |
||
65 | * Files that have already been fully processed. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $loaded = []; |
||
70 | |||
71 | /** |
||
72 | * Files that have already been partially processed. |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | protected $loadedNoDev = []; |
||
77 | |||
78 | /* ------------------------------------------------------------------------------------------------ |
||
79 | | Main Functions |
||
80 | | ------------------------------------------------------------------------------------------------ |
||
81 | */ |
||
82 | /** |
||
83 | * Apply plugin modifications to composer |
||
84 | * |
||
85 | * @param \Composer\Composer $composer |
||
86 | * @param \Composer\IO\IOInterface $io |
||
87 | */ |
||
88 | 120 | public function activate(Composer $composer, IOInterface $io) |
|
94 | |||
95 | /** |
||
96 | * Returns an array of event names this subscriber wants to listen to. |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | 5 | public static function getSubscribedEvents() |
|
115 | |||
116 | /** |
||
117 | * Handle an event callback for initialization. |
||
118 | * |
||
119 | * @param \Composer\EventDispatcher\Event $event |
||
120 | */ |
||
121 | 30 | public function onInit(BaseEvent $event) |
|
130 | |||
131 | /** |
||
132 | * Handle an event callback for pre-dependency solving phase of an install |
||
133 | * or update by adding any duplicate package dependencies found during |
||
134 | * initial merge processing to the request that will be processed by the |
||
135 | * dependency solver. |
||
136 | * |
||
137 | * @param \Composer\Installer\InstallerEvent $event |
||
138 | */ |
||
139 | 95 | public function onDependencySolve(InstallerEvent $event) |
|
153 | |||
154 | /** |
||
155 | * Install requirements. |
||
156 | * |
||
157 | * @param \Composer\DependencyResolver\Request $request |
||
158 | * @param \Composer\Package\Link[] $links |
||
159 | * @param bool $dev |
||
160 | */ |
||
161 | 95 | private function installRequires(Request $request, array $links, $dev = false) |
|
171 | |||
172 | /** |
||
173 | * Handle an event callback for an install or update or dump-autoload command by checking |
||
174 | * for "merge-patterns" in the "extra" data and merging package contents if found. |
||
175 | * |
||
176 | * @param \Composer\Script\Event $event |
||
177 | */ |
||
178 | 100 | public function onInstallUpdateOrDump(ScriptEvent $event) |
|
194 | |||
195 | /** |
||
196 | * Find configuration files matching the configured glob patterns and |
||
197 | * merge their contents with the master package. |
||
198 | * |
||
199 | * @param array $patterns List of files/glob patterns |
||
200 | * @param bool $required Are the patterns required to match files? |
||
201 | * |
||
202 | * @throws \Arcanedev\Composer\Exceptions\MissingFileException |
||
203 | */ |
||
204 | 100 | protected function mergeFiles(array $patterns, $required = false) |
|
221 | |||
222 | /** |
||
223 | * Read a JSON file and merge its contents |
||
224 | * |
||
225 | * @param \Composer\Package\RootPackageInterface $root |
||
226 | * @param string $path |
||
227 | */ |
||
228 | 95 | private function mergeFile(RootPackageInterface $root, $path) |
|
260 | |||
261 | /** |
||
262 | * Handle an event callback following installation of a new package by |
||
263 | * checking to see if the package that was installed was our plugin. |
||
264 | * |
||
265 | * @param \Composer\Installer\PackageEvent $event |
||
266 | */ |
||
267 | 15 | public function onPostPackageInstall(PackageEvent $event) |
|
283 | |||
284 | /** |
||
285 | * Handle an event callback following an install or update command. If our |
||
286 | * plugin was installed during the run then trigger an update command to |
||
287 | * process any merge-patterns in the current config. |
||
288 | * |
||
289 | * @param \Composer\Script\Event $event |
||
290 | * |
||
291 | * @codeCoverageIgnore |
||
292 | */ |
||
293 | public function onPostInstallOrUpdate(ScriptEvent $event) |
||
303 | |||
304 | /** |
||
305 | * Run first install. |
||
306 | * |
||
307 | * @param \Composer\Script\Event $event |
||
308 | * |
||
309 | * @throws \Exception |
||
310 | * |
||
311 | * @codeCoverageIgnore |
||
312 | */ |
||
313 | private function runFirstInstall(ScriptEvent $event) |
||
335 | |||
336 | /* ------------------------------------------------------------------------------------------------ |
||
337 | | Check Functions |
||
338 | | ------------------------------------------------------------------------------------------------ |
||
339 | */ |
||
340 | /** |
||
341 | * Check the preferred install (source or dist). |
||
342 | * |
||
343 | * @param string $preferred |
||
344 | * |
||
345 | * @return bool |
||
346 | * |
||
347 | * @codeCoverageIgnore |
||
348 | */ |
||
349 | private function isPreferredInstall($preferred) |
||
353 | } |
||
354 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.