1 | <?php namespace Arcanedev\Composer; |
||
29 | class ComposerPlugin implements PluginInterface, EventSubscriberInterface |
||
30 | { |
||
31 | /* ------------------------------------------------------------------------------------------------ |
||
32 | | Constants |
||
33 | | ------------------------------------------------------------------------------------------------ |
||
34 | */ |
||
35 | /** |
||
36 | * Package name |
||
37 | */ |
||
38 | const PACKAGE_NAME = 'arcanedev/composer'; |
||
39 | |||
40 | /** |
||
41 | * Plugin key |
||
42 | */ |
||
43 | const PLUGIN_KEY = 'merge-plugin'; |
||
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Properties |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** @var \Composer\Composer */ |
||
50 | protected $composer; |
||
51 | |||
52 | /** @var \Arcanedev\Composer\Entities\PluginState */ |
||
53 | protected $state; |
||
54 | |||
55 | /** @var \Arcanedev\Composer\Utilities\Logger */ |
||
56 | protected $logger; |
||
57 | |||
58 | /** |
||
59 | * Files that have already been processed |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $loadedFiles = []; |
||
64 | |||
65 | /* ------------------------------------------------------------------------------------------------ |
||
66 | | Main Functions |
||
67 | | ------------------------------------------------------------------------------------------------ |
||
68 | */ |
||
69 | /** |
||
70 | * Apply plugin modifications to composer |
||
71 | * |
||
72 | * @param \Composer\Composer $composer |
||
73 | * @param \Composer\IO\IOInterface $io |
||
74 | */ |
||
75 | 110 | public function activate(Composer $composer, IOInterface $io) |
|
81 | |||
82 | /** |
||
83 | * Returns an array of event names this subscriber wants to listen to. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 13 | public static function getSubscribedEvents() |
|
99 | |||
100 | /** |
||
101 | * Handle an event callback for pre-dependency solving phase of an install |
||
102 | * or update by adding any duplicate package dependencies found during |
||
103 | * initial merge processing to the request that will be processed by the |
||
104 | * dependency solver. |
||
105 | * |
||
106 | * @param \Composer\Installer\InstallerEvent $event |
||
107 | */ |
||
108 | 85 | public function onDependencySolve(InstallerEvent $event) |
|
122 | |||
123 | /** |
||
124 | * Install requirements. |
||
125 | * |
||
126 | * @param \Composer\DependencyResolver\Request $request |
||
127 | * @param \Composer\Package\Link[] $links |
||
128 | * @param bool $dev |
||
129 | */ |
||
130 | 85 | private function installRequires(Request $request, array $links, $dev = false) |
|
140 | |||
141 | /** |
||
142 | * Handle an event callback for an install or update or dump-autoload command by checking |
||
143 | * for "merge-patterns" in the "extra" data and merging package contents if found. |
||
144 | * |
||
145 | * @param \Composer\Script\Event $event |
||
146 | */ |
||
147 | 90 | public function onInstallUpdateOrDump(Event $event) |
|
163 | |||
164 | /** |
||
165 | * Find configuration files matching the configured glob patterns and |
||
166 | * merge their contents with the master package. |
||
167 | * |
||
168 | * @param array $patterns List of files/glob patterns |
||
169 | * @param bool $required Are the patterns required to match files? |
||
170 | * |
||
171 | * @throws \Arcanedev\Composer\Exceptions\MissingFileException |
||
172 | */ |
||
173 | 90 | protected function mergeFiles(array $patterns, $required = false) |
|
190 | |||
191 | /** |
||
192 | * Read a JSON file and merge its contents |
||
193 | * |
||
194 | * @param \Composer\Package\RootPackageInterface $root |
||
195 | * @param string $path |
||
196 | */ |
||
197 | 85 | private function mergeFile(RootPackageInterface $root, $path) |
|
215 | |||
216 | /** |
||
217 | * Handle an event callback following installation of a new package by |
||
218 | * checking to see if the package that was installed was our plugin. |
||
219 | * |
||
220 | * @param \Composer\Installer\PackageEvent $event |
||
221 | */ |
||
222 | 15 | public function onPostPackageInstall(PackageEvent $event) |
|
238 | |||
239 | /** |
||
240 | * Handle an event callback following an install or update command. If our |
||
241 | * plugin was installed during the run then trigger an update command to |
||
242 | * process any merge-patterns in the current config. |
||
243 | * |
||
244 | * @param \Composer\Script\Event $event |
||
245 | * |
||
246 | * @codeCoverageIgnore |
||
247 | */ |
||
248 | public function onPostInstallOrUpdate(Event $event) |
||
258 | |||
259 | /** |
||
260 | * Run first install. |
||
261 | * |
||
262 | * @param \Composer\Script\Event $event |
||
263 | * |
||
264 | * @throws \Exception |
||
265 | * |
||
266 | * @codeCoverageIgnore |
||
267 | */ |
||
268 | private function runFirstInstall(Event $event) |
||
290 | |||
291 | /* ------------------------------------------------------------------------------------------------ |
||
292 | | Check Functions |
||
293 | | ------------------------------------------------------------------------------------------------ |
||
294 | */ |
||
295 | /** |
||
296 | * Check the preferred install (source or dist). |
||
297 | * |
||
298 | * @param string $preferred |
||
299 | * |
||
300 | * @return bool |
||
301 | * |
||
302 | * @codeCoverageIgnore |
||
303 | */ |
||
304 | private function isPreferredInstall($preferred) |
||
308 | } |
||
309 |