1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
5
|
|
|
*/ |
6
|
|
|
namespace Vaimo\ComposerPatches\Repository\PatchesApplier\ListResolvers; |
7
|
|
|
|
8
|
|
|
class InvertedListResolver implements \Vaimo\ComposerPatches\Interfaces\ListResolverInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer |
12
|
|
|
*/ |
13
|
|
|
private $patchListTransformer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \Vaimo\ComposerPatches\Utils\PatchListUtils |
17
|
|
|
*/ |
18
|
|
|
private $patchListUtils; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \Vaimo\ComposerPatches\Interfaces\ListResolverInterface |
22
|
|
|
*/ |
23
|
|
|
private $baseResolver; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
\Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver |
30
|
|
|
) { |
31
|
|
|
$this->baseResolver = $baseResolver; |
32
|
|
|
|
33
|
|
|
$this->patchListTransformer = new \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer(); |
34
|
|
|
$this->patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function resolvePatchesQueue(array $patches) |
38
|
|
|
{ |
39
|
|
|
$exclusions = $this->baseResolver->resolvePatchesQueue($patches); |
40
|
|
|
|
41
|
|
|
foreach ($exclusions as $target => $items) { |
42
|
|
|
$patches[$target] = array_diff_key($patches[$target], $items); |
43
|
|
|
} |
44
|
|
|
return $patches; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function resolveRelevantPatches(array $patches, array $subset) |
48
|
|
|
{ |
49
|
|
|
return $this->patchListUtils->intersectListsByPath($patches, $subset); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function resolveInitialState(array $patches, array $state) |
53
|
|
|
{ |
54
|
|
|
$patchesByTarget = $this->patchListTransformer->groupItemsByTarget($patches); |
55
|
|
|
|
56
|
|
|
$unpackedState = $this->patchListTransformer->createDetailedList($state); |
57
|
|
|
|
58
|
|
|
$updates = array(); |
59
|
|
|
|
60
|
|
|
foreach ($patchesByTarget as $target => $group) { |
61
|
|
|
foreach ($group as $path => $item) { |
62
|
|
|
if (isset($unpackedState[$target][$path])) { |
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (!isset($updates[$target])) { |
67
|
|
|
$updates[$target] = array(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$updates[$target][$path] = $item; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->patchListUtils->mergeLists( |
75
|
|
|
$state, |
76
|
|
|
$this->patchListTransformer->createSimplifiedList($updates) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|