1
|
|
|
<?php namespace Arcanedev\Composer\Entities\PackageTraits; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Composer\Entities\PluginState; |
4
|
|
|
use Arcanedev\Composer\Utilities\NestedArray; |
5
|
|
|
use Composer\Package\RootPackageInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait ExtraTrait |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\Composer\Entities\PackageTraits |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
trait ExtraTrait |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Traits |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
use PackageTrait; |
20
|
|
|
|
21
|
|
|
/* ------------------------------------------------------------------------------------------------ |
22
|
|
|
| Main Functions |
23
|
|
|
| ------------------------------------------------------------------------------------------------ |
24
|
|
|
*/ |
25
|
|
|
/** |
26
|
|
|
* Merge extra config into a RootPackage. |
27
|
|
|
* |
28
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
29
|
|
|
* @param \Arcanedev\Composer\Entities\PluginState $state |
30
|
|
|
*/ |
31
|
99 |
|
protected function mergeExtra(RootPackageInterface $root, PluginState $state) |
32
|
|
|
{ |
33
|
99 |
|
$extra = $this->getPackage()->getExtra(); |
34
|
99 |
|
unset($extra['merge-plugin']); |
35
|
|
|
|
36
|
99 |
|
if ($state->shouldMergeExtra() && ! empty($extra)) { |
37
|
18 |
|
$unwrapped = static::unwrapIfNeeded($root, 'setExtra'); |
38
|
18 |
|
$unwrapped->setExtra( |
39
|
18 |
|
$this->getExtra($unwrapped, $state, $extra) |
40
|
|
|
); |
41
|
|
|
} |
42
|
99 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get extra config. |
46
|
|
|
* |
47
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
48
|
|
|
* @param \Arcanedev\Composer\Entities\PluginState $state |
49
|
|
|
* @param array $extra |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
18 |
|
private function getExtra( |
54
|
|
|
RootPackageInterface $root, PluginState $state, $extra |
55
|
|
|
) { |
56
|
18 |
|
$rootExtra = $root->getExtra(); |
57
|
|
|
|
58
|
18 |
|
if ($state->replaceDuplicateLinks()) { |
59
|
6 |
|
return self::mergeExtraArray($state->shouldMergeExtraDeep(), $rootExtra, $extra); |
60
|
|
|
} |
61
|
|
|
|
62
|
12 |
|
if ( ! $state->shouldMergeExtraDeep()) { |
63
|
9 |
|
foreach (array_intersect(array_keys($extra), array_keys($rootExtra)) as $key) { |
64
|
3 |
|
$this->getLogger()->info( |
65
|
3 |
|
"Ignoring duplicate <comment>{$key}</comment> in ". |
66
|
3 |
|
"<comment>{$this->getPath()}</comment> extra config." |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
12 |
|
return static::mergeExtraArray($state->shouldMergeExtraDeep(), $extra, $rootExtra); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Merges two arrays either via arrayMergeDeep or via array_merge. |
76
|
|
|
* |
77
|
|
|
* @param bool $mergeDeep |
78
|
|
|
* @param array $array1 |
79
|
|
|
* @param array $array2 |
80
|
|
|
* |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
18 |
|
private static function mergeExtraArray($mergeDeep, $array1, $array2) |
84
|
|
|
{ |
85
|
18 |
|
return $mergeDeep |
86
|
6 |
|
? NestedArray::mergeDeep($array1, $array2) |
87
|
18 |
|
: array_merge($array1, $array2); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|