|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Composer Merge plugin. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2015 Bryan Davis, Wikimedia Foundation, and contributors |
|
6
|
|
|
* |
|
7
|
|
|
* This software may be modified and distributed under the terms of the MIT |
|
8
|
|
|
* license. See the LICENSE file for details. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Wikimedia\Composer\Merge; |
|
12
|
|
|
|
|
13
|
|
|
use Wikimedia\Composer\Logger; |
|
14
|
|
|
|
|
15
|
|
|
use Composer\Composer; |
|
16
|
|
|
use Composer\Json\JsonFile; |
|
17
|
|
|
use Composer\Package\BasePackage; |
|
18
|
|
|
use Composer\Package\CompletePackage; |
|
19
|
|
|
use Composer\Package\Link; |
|
20
|
|
|
use Composer\Package\Loader\ArrayLoader; |
|
21
|
|
|
use Composer\Package\RootAliasPackage; |
|
22
|
|
|
use Composer\Package\RootPackage; |
|
23
|
|
|
use Composer\Package\RootPackageInterface; |
|
24
|
|
|
use Composer\Package\Version\VersionParser; |
|
25
|
|
|
use UnexpectedValueException; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Processing for a composer.json file that will be merged into |
|
29
|
|
|
* a RootPackageInterface |
|
30
|
|
|
* |
|
31
|
|
|
* @author Bryan Davis <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class ExtraPackage |
|
34
|
|
|
{ |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Composer $composer |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $composer; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Logger $logger |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $logger; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string $path |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $path; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var array $json |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $json; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var CompletePackage $package |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $package; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $path Path to composer.json file |
|
63
|
|
|
* @param Composer $composer |
|
64
|
|
|
* @param Logger $logger |
|
65
|
|
|
*/ |
|
66
|
90 |
|
public function __construct($path, Composer $composer, Logger $logger) |
|
67
|
|
|
{ |
|
68
|
90 |
|
$this->path = $path; |
|
69
|
90 |
|
$this->composer = $composer; |
|
70
|
90 |
|
$this->logger = $logger; |
|
71
|
90 |
|
$this->json = $this->readPackageJson($path); |
|
72
|
90 |
|
$this->package = $this->loadPackage($this->json); |
|
|
|
|
|
|
73
|
90 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get list of additional packages to include if precessing recursively. |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
85 |
|
public function getIncludes() |
|
81
|
|
|
{ |
|
82
|
85 |
|
return isset($this->json['extra']['merge-plugin']['include']) ? |
|
83
|
85 |
|
$this->json['extra']['merge-plugin']['include'] : array(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get list of additional packages to require if precessing recursively. |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
85 |
|
public function getRequires() |
|
92
|
|
|
{ |
|
93
|
85 |
|
return isset($this->json['extra']['merge-plugin']['require']) ? |
|
94
|
85 |
|
$this->json['extra']['merge-plugin']['require'] : array(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Read the contents of a composer.json style file into an array. |
|
99
|
|
|
* |
|
100
|
|
|
* The package contents are fixed up to be usable to create a Package |
|
101
|
|
|
* object by providing dummy "name" and "version" values if they have not |
|
102
|
|
|
* been provided in the file. This is consistent with the default root |
|
103
|
|
|
* package loading behavior of Composer. |
|
104
|
|
|
* |
|
105
|
|
|
* @param string $path |
|
106
|
|
|
* @return array |
|
107
|
|
|
*/ |
|
108
|
90 |
|
protected function readPackageJson($path) |
|
109
|
|
|
{ |
|
110
|
90 |
|
$file = new JsonFile($path); |
|
111
|
90 |
|
$json = $file->read(); |
|
112
|
90 |
|
if (!isset($json['name'])) { |
|
113
|
85 |
|
$json['name'] = 'merge-plugin/' . |
|
114
|
85 |
|
strtr($path, DIRECTORY_SEPARATOR, '-'); |
|
115
|
85 |
|
} |
|
116
|
90 |
|
if (!isset($json['version'])) { |
|
117
|
90 |
|
$json['version'] = '1.0.0'; |
|
118
|
90 |
|
} |
|
119
|
90 |
|
return $json; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param string $json |
|
124
|
|
|
* @return CompletePackage |
|
125
|
|
|
*/ |
|
126
|
90 |
|
protected function loadPackage($json) |
|
127
|
|
|
{ |
|
128
|
90 |
|
$loader = new ArrayLoader(); |
|
129
|
90 |
|
$package = $loader->load($json); |
|
|
|
|
|
|
130
|
|
|
// @codeCoverageIgnoreStart |
|
131
|
|
|
if (!$package instanceof CompletePackage) { |
|
132
|
|
|
throw new UnexpectedValueException( |
|
133
|
|
|
'Expected instance of CompletePackage, got ' . |
|
134
|
|
|
get_class($package) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
// @codeCoverageIgnoreEnd |
|
138
|
90 |
|
return $package; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Merge this package into a RootPackageInterface |
|
143
|
|
|
* |
|
144
|
|
|
* @param RootPackageInterface $root |
|
145
|
|
|
* @param PluginState $state |
|
146
|
|
|
*/ |
|
147
|
90 |
|
public function mergeInto(RootPackageInterface $root, PluginState $state) |
|
148
|
|
|
{ |
|
149
|
90 |
|
$this->addRepositories($root); |
|
150
|
|
|
|
|
151
|
90 |
|
$this->mergeRequires('require', $root, $state); |
|
152
|
90 |
|
if ($state->isDevMode()) { |
|
153
|
85 |
|
$this->mergeRequires('require-dev', $root, $state); |
|
154
|
85 |
|
} |
|
155
|
|
|
|
|
156
|
90 |
|
$this->mergePackageLinks('conflict', $root); |
|
157
|
90 |
|
$this->mergePackageLinks('replace', $root); |
|
158
|
90 |
|
$this->mergePackageLinks('provide', $root); |
|
159
|
|
|
|
|
160
|
90 |
|
$this->mergeSuggests($root); |
|
161
|
|
|
|
|
162
|
90 |
|
$this->mergeAutoload('autoload', $root); |
|
163
|
90 |
|
if ($state->isDevMode()) { |
|
164
|
85 |
|
$this->mergeAutoload('devAutoload', $root); |
|
165
|
85 |
|
} |
|
166
|
|
|
|
|
167
|
90 |
|
$this->mergeExtra($root, $state); |
|
168
|
90 |
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Add a collection of repositories described by the given configuration |
|
172
|
|
|
* to the given package and the global repository manager. |
|
173
|
|
|
* |
|
174
|
|
|
* @param RootPackageInterface $root |
|
175
|
|
|
*/ |
|
176
|
90 |
|
protected function addRepositories(RootPackageInterface $root) |
|
177
|
|
|
{ |
|
178
|
90 |
|
if (!isset($this->json['repositories'])) { |
|
179
|
80 |
|
return; |
|
180
|
|
|
} |
|
181
|
10 |
|
$repoManager = $this->composer->getRepositoryManager(); |
|
182
|
10 |
|
$newRepos = array(); |
|
183
|
|
|
|
|
184
|
10 |
|
foreach ($this->json['repositories'] as $repoJson) { |
|
185
|
10 |
|
if (!isset($repoJson['type'])) { |
|
186
|
10 |
|
continue; |
|
187
|
|
|
} |
|
188
|
10 |
|
$this->logger->info("Adding {$repoJson['type']} repository"); |
|
189
|
10 |
|
$repo = $repoManager->createRepository( |
|
190
|
10 |
|
$repoJson['type'], |
|
191
|
|
|
$repoJson |
|
192
|
10 |
|
); |
|
193
|
10 |
|
$repoManager->addRepository($repo); |
|
194
|
10 |
|
$newRepos[] = $repo; |
|
195
|
10 |
|
} |
|
196
|
|
|
|
|
197
|
10 |
|
$unwrapped = self::unwrapIfNeeded($root, 'setRepositories'); |
|
198
|
10 |
|
$unwrapped->setRepositories(array_merge( |
|
199
|
10 |
|
$newRepos, |
|
200
|
10 |
|
$root->getRepositories() |
|
201
|
10 |
|
)); |
|
202
|
10 |
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Merge require or require-dev into a RootPackageInterface |
|
206
|
|
|
* |
|
207
|
|
|
* @param string $type 'require' or 'require-dev' |
|
208
|
|
|
* @param RootPackageInterface $root |
|
209
|
|
|
* @param PluginState $state |
|
210
|
|
|
*/ |
|
211
|
90 |
|
protected function mergeRequires( |
|
212
|
|
|
$type, |
|
213
|
|
|
RootPackageInterface $root, |
|
214
|
|
|
PluginState $state |
|
215
|
|
|
) { |
|
216
|
90 |
|
$linkType = BasePackage::$supportedLinkTypes[$type]; |
|
217
|
90 |
|
$getter = 'get' . ucfirst($linkType['method']); |
|
218
|
90 |
|
$setter = 'set' . ucfirst($linkType['method']); |
|
219
|
|
|
|
|
220
|
90 |
|
$requires = $this->package->{$getter}(); |
|
221
|
90 |
|
if (empty($requires)) { |
|
222
|
75 |
|
return; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
60 |
|
$this->mergeStabilityFlags($root, $requires); |
|
226
|
|
|
|
|
227
|
60 |
|
$requires = $this->replaceSelfVersionDependencies( |
|
228
|
60 |
|
$type, |
|
229
|
60 |
|
$requires, |
|
230
|
|
|
$root |
|
231
|
60 |
|
); |
|
232
|
|
|
|
|
233
|
60 |
|
$root->{$setter}($this->mergeOrDefer( |
|
234
|
60 |
|
$type, |
|
235
|
60 |
|
$root->{$getter}(), |
|
236
|
60 |
|
$requires, |
|
237
|
|
|
$state |
|
238
|
60 |
|
)); |
|
239
|
60 |
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Merge two collections of package links and collect duplicates for |
|
243
|
|
|
* subsequent processing. |
|
244
|
|
|
* |
|
245
|
|
|
* @param string $type 'require' or 'require-dev' |
|
246
|
|
|
* @param array $origin Primary collection |
|
247
|
|
|
* @param array $merge Additional collection |
|
248
|
|
|
* @param PluginState $state |
|
249
|
|
|
* @return array Merged collection |
|
250
|
|
|
*/ |
|
251
|
60 |
|
protected function mergeOrDefer( |
|
252
|
|
|
$type, |
|
253
|
|
|
array $origin, |
|
254
|
|
|
array $merge, |
|
255
|
|
|
$state |
|
256
|
|
|
) { |
|
257
|
60 |
|
$dups = array(); |
|
258
|
60 |
|
foreach ($merge as $name => $link) { |
|
259
|
60 |
|
if (!isset($origin[$name]) || $state->replaceDuplicateLinks()) { |
|
260
|
60 |
|
$this->logger->info("Merging <comment>{$name}</comment>"); |
|
261
|
60 |
|
$origin[$name] = $link; |
|
262
|
60 |
|
} else { |
|
263
|
|
|
// Defer to solver. |
|
264
|
15 |
|
$this->logger->info( |
|
265
|
15 |
|
"Deferring duplicate <comment>{$name}</comment>" |
|
266
|
15 |
|
); |
|
267
|
15 |
|
$dups[] = $link; |
|
268
|
|
|
} |
|
269
|
60 |
|
} |
|
270
|
60 |
|
$state->addDuplicateLinks($type, $dups); |
|
271
|
60 |
|
return $origin; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Merge autoload or autoload-dev into a RootPackageInterface |
|
276
|
|
|
* |
|
277
|
|
|
* @param string $type 'autoload' or 'devAutoload' |
|
278
|
|
|
* @param RootPackageInterface $root |
|
279
|
|
|
*/ |
|
280
|
90 |
|
protected function mergeAutoload($type, RootPackageInterface $root) |
|
281
|
|
|
{ |
|
282
|
90 |
|
$getter = 'get' . ucfirst($type); |
|
283
|
90 |
|
$setter = 'set' . ucfirst($type); |
|
284
|
|
|
|
|
285
|
90 |
|
$autoload = $this->package->{$getter}(); |
|
286
|
90 |
|
if (empty($autoload)) { |
|
287
|
85 |
|
return; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
10 |
|
$unwrapped = self::unwrapIfNeeded($root, $setter); |
|
291
|
10 |
|
$unwrapped->{$setter}(array_merge_recursive( |
|
292
|
10 |
|
$root->{$getter}(), |
|
293
|
10 |
|
$this->fixRelativePaths($autoload) |
|
294
|
10 |
|
)); |
|
295
|
10 |
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* Fix a collection of paths that are relative to this package to be |
|
299
|
|
|
* relative to the base package. |
|
300
|
|
|
* |
|
301
|
|
|
* @param array $paths |
|
302
|
|
|
* @return array |
|
303
|
|
|
*/ |
|
304
|
10 |
|
protected function fixRelativePaths(array $paths) |
|
305
|
|
|
{ |
|
306
|
10 |
|
$base = dirname($this->path); |
|
307
|
10 |
|
$base = ($base === '.') ? '' : "{$base}/"; |
|
308
|
|
|
|
|
309
|
10 |
|
array_walk_recursive( |
|
310
|
10 |
|
$paths, |
|
311
|
|
|
function (&$path) use ($base) { |
|
312
|
10 |
|
$path = "{$base}{$path}"; |
|
313
|
10 |
|
} |
|
314
|
10 |
|
); |
|
315
|
10 |
|
return $paths; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Extract and merge stability flags from the given collection of |
|
320
|
|
|
* requires and merge them into a RootPackageInterface |
|
321
|
|
|
* |
|
322
|
|
|
* @param RootPackageInterface $root |
|
323
|
|
|
* @param array $requires |
|
324
|
|
|
*/ |
|
325
|
60 |
|
protected function mergeStabilityFlags( |
|
326
|
|
|
RootPackageInterface $root, |
|
327
|
|
|
array $requires |
|
328
|
|
|
) { |
|
329
|
60 |
|
$flags = $root->getStabilityFlags(); |
|
330
|
60 |
|
$sf = new StabilityFlags($flags, $root->getMinimumStability()); |
|
331
|
|
|
|
|
332
|
60 |
|
$unwrapped = self::unwrapIfNeeded($root, 'setStabilityFlags'); |
|
333
|
60 |
|
$unwrapped->setStabilityFlags(array_merge( |
|
334
|
60 |
|
$flags, |
|
335
|
60 |
|
$sf->extractAll($requires) |
|
336
|
60 |
|
)); |
|
337
|
60 |
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* Merge package links of the given type into a RootPackageInterface |
|
341
|
|
|
* |
|
342
|
|
|
* @param string $type 'conflict', 'replace' or 'provide' |
|
343
|
|
|
* @param RootPackageInterface $root |
|
344
|
|
|
*/ |
|
345
|
90 |
|
protected function mergePackageLinks($type, RootPackageInterface $root) |
|
346
|
|
|
{ |
|
347
|
90 |
|
$linkType = BasePackage::$supportedLinkTypes[$type]; |
|
348
|
90 |
|
$getter = 'get' . ucfirst($linkType['method']); |
|
349
|
90 |
|
$setter = 'set' . ucfirst($linkType['method']); |
|
350
|
|
|
|
|
351
|
90 |
|
$links = $this->package->{$getter}(); |
|
352
|
90 |
|
if (!empty($links)) { |
|
353
|
20 |
|
$unwrapped = self::unwrapIfNeeded($root, $setter); |
|
354
|
|
|
// @codeCoverageIgnoreStart |
|
355
|
|
|
if ($root !== $unwrapped) { |
|
356
|
|
|
$this->logger->warning( |
|
357
|
|
|
'This Composer version does not support ' . |
|
358
|
|
|
"'{$type}' merging for aliased packages." |
|
359
|
|
|
); |
|
360
|
|
|
} |
|
361
|
|
|
// @codeCoverageIgnoreEnd |
|
362
|
20 |
|
$unwrapped->{$setter}(array_merge( |
|
363
|
20 |
|
$root->{$getter}(), |
|
364
|
20 |
|
$this->replaceSelfVersionDependencies($type, $links, $root) |
|
365
|
20 |
|
)); |
|
366
|
20 |
|
} |
|
367
|
90 |
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* Merge suggested packages into a RootPackageInterface |
|
371
|
|
|
* |
|
372
|
|
|
* @param RootPackageInterface $root |
|
373
|
|
|
*/ |
|
374
|
90 |
|
protected function mergeSuggests(RootPackageInterface $root) |
|
375
|
|
|
{ |
|
376
|
90 |
|
$suggests = $this->package->getSuggests(); |
|
377
|
90 |
|
if (!empty($suggests)) { |
|
378
|
10 |
|
$unwrapped = self::unwrapIfNeeded($root, 'setSuggests'); |
|
379
|
10 |
|
$unwrapped->setSuggests(array_merge( |
|
380
|
10 |
|
$root->getSuggests(), |
|
381
|
|
|
$suggests |
|
382
|
10 |
|
)); |
|
383
|
10 |
|
} |
|
384
|
90 |
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* Merge extra config into a RootPackageInterface |
|
388
|
|
|
* |
|
389
|
|
|
* @param RootPackageInterface $root |
|
390
|
|
|
* @param PluginState $state |
|
391
|
|
|
*/ |
|
392
|
90 |
|
public function mergeExtra(RootPackageInterface $root, PluginState $state) |
|
393
|
|
|
{ |
|
394
|
90 |
|
$extra = $this->package->getExtra(); |
|
395
|
90 |
|
unset($extra['merge-plugin']); |
|
396
|
90 |
|
if (!$state->shouldMergeExtra() || empty($extra)) { |
|
397
|
75 |
|
return; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
15 |
|
$rootExtra = $root->getExtra(); |
|
401
|
15 |
|
$unwrapped = self::unwrapIfNeeded($root, 'setExtra'); |
|
402
|
|
|
|
|
403
|
15 |
|
if ($state->replaceDuplicateLinks()) { |
|
404
|
5 |
|
$unwrapped->setExtra( |
|
405
|
5 |
|
array_merge($rootExtra, $extra) |
|
406
|
5 |
|
); |
|
407
|
|
|
|
|
408
|
5 |
|
} elseif ($state->shouldMergeDeep()) { |
|
409
|
10 |
|
$unwrapped->setExtra( |
|
410
|
10 |
|
$this->arrayMergeDeep($extra, $rootExtra) |
|
411
|
10 |
|
); |
|
412
|
10 |
|
} else { |
|
413
|
5 |
|
foreach (array_intersect( |
|
414
|
5 |
|
array_keys($extra), |
|
415
|
5 |
|
array_keys($rootExtra) |
|
416
|
5 |
|
) as $key) { |
|
417
|
10 |
|
$this->logger->info( |
|
418
|
10 |
|
"Ignoring duplicate <comment>{$key}</comment> in ". |
|
419
|
10 |
|
"<comment>{$this->path}</comment> extra config." |
|
420
|
10 |
|
); |
|
421
|
|
|
} |
|
422
|
15 |
|
$unwrapped->setExtra( |
|
423
|
|
|
array_merge($extra, $rootExtra) |
|
424
|
|
|
); |
|
425
|
|
|
} |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* Merges multiple arrays, recursively, and returns the merged array. |
|
430
|
|
|
* |
|
431
|
|
|
* This function is similar to PHP's array_merge_recursive() function, but it |
|
432
|
|
|
* handles non-array values differently. When merging values that are not both |
|
433
|
70 |
|
* arrays, the latter value replaces the former rather than merging with it. |
|
434
|
|
|
* |
|
435
|
|
|
* Example: |
|
436
|
|
|
* @code |
|
437
|
|
|
* $link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => t('X'), 'class' => array('a', 'b'))); |
|
438
|
70 |
|
* $link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('c', 'd'))); |
|
439
|
70 |
|
* |
|
440
|
70 |
|
* // This results in array( |
|
441
|
70 |
|
* // 'fragment' => array('x', 'y'), |
|
442
|
|
|
* // 'attributes' => array('title' => array(t('X'), t('Y')), 'class' => array('a', 'b', 'c', 'd')) |
|
443
|
70 |
|
* // ). |
|
444
|
70 |
|
* $incorrect = array_merge_recursive($link_options_1, $link_options_2); |
|
445
|
|
|
* |
|
446
|
70 |
|
* // This results in array( |
|
447
|
70 |
|
* // 'fragment' => 'y', |
|
448
|
70 |
|
* // 'attributes' => array('title' => t('Y'), 'class' => array('a', 'b', 'c', 'd')) |
|
449
|
10 |
|
* // ). |
|
450
|
|
|
* $correct = $this->arrayMergeDeep($link_options_1, $link_options_2); |
|
451
|
5 |
|
* @endcode |
|
452
|
5 |
|
* |
|
453
|
5 |
|
* Note: This function was derived from Drupal's drupal_array_merge_deep(). |
|
454
|
5 |
|
* |
|
455
|
5 |
|
* @param array ... |
|
456
|
5 |
|
* Arrays to merge. |
|
457
|
5 |
|
* |
|
458
|
5 |
|
* @return array |
|
459
|
|
|
* The merged array. |
|
460
|
|
|
*/ |
|
461
|
5 |
|
protected function arrayMergeDeep() |
|
462
|
5 |
|
{ |
|
463
|
5 |
|
$arrays = func_get_args(); |
|
464
|
5 |
|
$result = array(); |
|
465
|
5 |
|
|
|
466
|
|
|
foreach ($arrays as $array) { |
|
467
|
5 |
|
foreach ($array as $key => $value) { |
|
468
|
|
|
// Renumber integer keys as array_merge_recursive() does. Note that PHP |
|
469
|
70 |
|
// automatically converts array keys that are integer strings (e.g., '1') |
|
470
|
70 |
|
// to integers. |
|
471
|
|
|
if (is_integer($key)) { |
|
472
|
70 |
|
$result[] = $value; |
|
473
|
|
|
} elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { |
|
474
|
|
|
// Recurse when both values are arrays. |
|
475
|
|
|
$result[$key] = $this->arrayMergeDeep($result[$key], $value); |
|
476
|
|
|
} else { |
|
477
|
|
|
// Otherwise, use the latter value, overriding any previous value. |
|
478
|
|
|
$result[$key] = $value; |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
return $result; |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
/** |
|
487
|
|
|
* Update Links with a 'self.version' constraint with the root package's |
|
488
|
|
|
* version. |
|
489
|
|
|
* |
|
490
|
|
|
* @param string $type Link type |
|
491
|
|
|
* @param array $links |
|
492
|
90 |
|
* @param RootPackageInterface $root |
|
493
|
|
|
* @return array |
|
494
|
|
|
*/ |
|
495
|
|
|
protected function replaceSelfVersionDependencies( |
|
496
|
|
|
$type, |
|
497
|
|
|
array $links, |
|
498
|
|
|
RootPackageInterface $root |
|
499
|
|
|
) { |
|
500
|
|
|
$linkType = BasePackage::$supportedLinkTypes[$type]; |
|
501
|
|
|
$version = $root->getVersion(); |
|
502
|
|
|
$prettyVersion = $root->getPrettyVersion(); |
|
503
|
|
|
$vp = new VersionParser(); |
|
504
|
90 |
|
|
|
505
|
|
|
$method = 'get' . ucfirst($linkType['method']); |
|
506
|
|
|
$packages = $root->$method(); |
|
507
|
|
|
|
|
508
|
|
|
return array_map( |
|
509
|
|
|
function ($link) use ($linkType, $version, $prettyVersion, $vp, $packages) { |
|
510
|
|
|
if ('self.version' === $link->getPrettyConstraint()) { |
|
511
|
|
|
if (isset($packages[$link->getSource()])) { |
|
512
|
|
|
/** @var Link $package */ |
|
513
|
|
|
$package = $packages[$link->getSource()]; |
|
514
|
|
|
return new Link( |
|
515
|
|
|
$link->getSource(), |
|
516
|
|
|
$link->getTarget(), |
|
517
|
|
|
$vp->parseConstraints($package->getConstraint()->getPrettyString()), |
|
518
|
|
|
$linkType['description'], |
|
519
|
|
|
$package->getPrettyConstraint() |
|
520
|
|
|
); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
return new Link( |
|
524
|
|
|
$link->getSource(), |
|
525
|
|
|
$link->getTarget(), |
|
526
|
|
|
$vp->parseConstraints($version), |
|
527
|
|
|
$linkType['description'], |
|
528
|
|
|
$prettyVersion |
|
529
|
|
|
); |
|
530
|
|
|
} |
|
531
|
|
|
return $link; |
|
532
|
|
|
}, |
|
533
|
|
|
$links |
|
534
|
|
|
); |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
/** |
|
538
|
|
|
* Get a full featured Package from a RootPackageInterface. |
|
539
|
|
|
* |
|
540
|
|
|
* In Composer versions before 599ad77 the RootPackageInterface only |
|
541
|
|
|
* defines a sub-set of operations needed by composer-merge-plugin and |
|
542
|
|
|
* RootAliasPackage only implemented those methods defined by the |
|
543
|
|
|
* interface. Most of the unimplemented methods in RootAliasPackage can be |
|
544
|
|
|
* worked around because the getter methods that are implemented proxy to |
|
545
|
|
|
* the aliased package which we can modify by unwrapping. The exception |
|
546
|
|
|
* being modifying the 'conflicts', 'provides' and 'replaces' collections. |
|
547
|
|
|
* We have no way to actually modify those collections unfortunately in |
|
548
|
|
|
* older versions of Composer. |
|
549
|
|
|
* |
|
550
|
|
|
* @param RootPackageInterface $root |
|
551
|
|
|
* @param string $method Method needed |
|
552
|
|
|
* @return RootPackageInterface|RootPackage |
|
553
|
|
|
*/ |
|
554
|
|
|
public static function unwrapIfNeeded( |
|
555
|
|
|
RootPackageInterface $root, |
|
556
|
|
|
$method = 'setExtra' |
|
557
|
|
|
) { |
|
558
|
|
|
// @codeCoverageIgnoreStart |
|
559
|
|
|
if ($root instanceof RootAliasPackage && |
|
560
|
|
|
!method_exists($root, $method) |
|
561
|
|
|
) { |
|
562
|
|
|
// Unwrap and return the aliased RootPackage. |
|
563
|
|
|
$root = $root->getAliasOf(); |
|
564
|
|
|
} |
|
565
|
|
|
// @codeCoverageIgnoreEnd |
|
566
|
|
|
return $root; |
|
567
|
|
|
} |
|
568
|
|
|
} |
|
569
|
|
|
// vim:sw=4:ts=4:sts=4:et: |
|
570
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: