1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
5
|
|
|
*/ |
6
|
|
|
namespace Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents; |
7
|
|
|
|
8
|
|
|
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition; |
9
|
|
|
|
10
|
|
|
class PlatformComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Composer\Package\Version\VersionParser |
14
|
|
|
*/ |
15
|
|
|
private $versionParser; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Vaimo\ComposerPatches\Utils\ConstraintUtils |
19
|
|
|
*/ |
20
|
|
|
private $constraintUtils; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Composer\Package\PackageInterface[] |
24
|
|
|
*/ |
25
|
|
|
private $constraintPackages; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \Composer\Package\PackageInterface[] $constraintPackages |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
array $constraintPackages = array() |
32
|
|
|
) { |
33
|
|
|
$this->versionParser = new \Composer\Package\Version\VersionParser(); |
34
|
|
|
$this->constraintUtils = new \Vaimo\ComposerPatches\Utils\ConstraintUtils(); |
35
|
|
|
$this->constraintPackages = $constraintPackages; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $patches |
40
|
|
|
* @param \Composer\Package\PackageInterface[] $packagesByName |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function process(array $patches, array $packagesByName) |
44
|
|
|
{ |
45
|
|
|
/** @var \Composer\Package\CompletePackageInterface $rootPackage */ |
46
|
|
|
$packages = $this->constraintPackages; |
47
|
|
|
|
48
|
|
|
foreach ($patches as &$packagePatches) { |
49
|
|
|
foreach ($packagePatches as &$patchData) { |
50
|
|
|
$patchConstraints = $patchData[PatchDefinition::DEPENDS]; |
51
|
|
|
|
52
|
|
|
$this->resolveComparisonResults($patchConstraints, $packages); |
53
|
|
|
|
54
|
|
|
$comparisonResults = $this->resolveComparisonResults($patchConstraints, $packages); |
55
|
|
|
|
56
|
|
|
if (!$comparisonResults) { |
57
|
|
|
continue; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (count(array_filter($comparisonResults)) !== count($comparisonResults)) { |
61
|
|
|
$patchData = false; |
62
|
|
|
|
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$patchData[PatchDefinition::DEPENDS] = array_diff_key( |
67
|
|
|
$patchData[PatchDefinition::DEPENDS], |
68
|
|
|
array_filter($comparisonResults) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$packagePatches = array_filter($packagePatches); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return array_filter($patches); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function resolveComparisonResults(array $patchConstraints, array $packages) |
79
|
|
|
{ |
80
|
|
|
$comparisonResults = array(); |
81
|
|
|
|
82
|
|
|
foreach ($patchConstraints as $constraintTarget => &$version) { |
83
|
|
|
if (!isset($packages[$constraintTarget])) { |
84
|
|
|
continue; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$package = $packages[$constraintTarget]; |
88
|
|
|
$packageVersions = array($package->getVersion()); |
89
|
|
|
|
90
|
|
|
$matchResult = false; |
91
|
|
|
|
92
|
|
|
foreach (array_filter($packageVersions) as $packageVersion) { |
93
|
|
|
$packageConstraint = $this->versionParser->parseConstraints($packageVersion); |
94
|
|
|
$patchConstraint = $this->versionParser->parseConstraints($version); |
95
|
|
|
|
96
|
|
|
$matchResult = $patchConstraint->matches($packageConstraint); |
97
|
|
|
|
98
|
|
|
if ($matchResult) { |
99
|
|
|
break; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$comparisonResults[$constraintTarget] = $matchResult; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $comparisonResults; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|