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\Loader; |
7
|
|
|
|
8
|
|
|
use Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents; |
9
|
|
|
|
10
|
|
|
use Vaimo\ComposerPatches\Config as PluginConfig; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
14
|
|
|
*/ |
15
|
|
|
class ComponentPool |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Composer\Composer |
19
|
|
|
*/ |
20
|
|
|
private $composer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Composer\IO\IOInterface |
24
|
|
|
*/ |
25
|
|
|
private $appIO; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var bool[]|\Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface[] |
29
|
|
|
*/ |
30
|
|
|
private $components = array(); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var bool |
34
|
|
|
*/ |
35
|
|
|
private $gracefulMode; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
39
|
|
|
* |
40
|
|
|
* @param \Composer\Composer $composer |
41
|
|
|
* @param \Composer\IO\IOInterface $appIO |
42
|
|
|
* @param bool $gracefulMode |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
\Composer\Composer $composer, |
46
|
|
|
\Composer\IO\IOInterface $appIO, |
47
|
|
|
$gracefulMode = false |
48
|
|
|
) { |
49
|
|
|
$this->composer = $composer; |
50
|
|
|
$this->appIO = $appIO; |
51
|
|
|
$this->gracefulMode = $gracefulMode; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getList(PluginConfig $pluginConfig) |
55
|
|
|
{ |
56
|
|
|
$patcherConfig = $pluginConfig->getPatcherConfig(); |
57
|
|
|
|
58
|
|
|
$composerConfig = clone $this->composer->getConfig(); |
59
|
|
|
|
60
|
|
|
$composerConfig->merge(array( |
61
|
|
|
'config' => array('secure-http' => $patcherConfig[PluginConfig::PATCHER_SECURE_HTTP]) |
62
|
|
|
)); |
63
|
|
|
|
64
|
|
|
$rootPackage = $this->composer->getPackage(); |
65
|
|
|
$extra = $rootPackage->getExtra(); |
66
|
|
|
|
67
|
|
|
if (isset($extra['excluded-patches']) && !isset($extra[PluginConfig::EXCLUDED_PATCHES])) { |
68
|
|
|
$extra[PluginConfig::EXCLUDED_PATCHES] = $extra['excluded-patches']; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$excludes = isset($extra[PluginConfig::EXCLUDED_PATCHES]) |
72
|
|
|
? $extra[PluginConfig::EXCLUDED_PATCHES] |
73
|
|
|
: array(); |
74
|
|
|
|
75
|
|
|
$installationManager = $this->composer->getInstallationManager(); |
76
|
|
|
$composerConfig = clone $this->composer->getConfig(); |
77
|
|
|
|
78
|
|
|
$cache = null; |
79
|
|
|
|
80
|
|
|
if ($composerConfig->get('cache-files-ttl') > 0) { |
81
|
|
|
$cache = new \Composer\Cache( |
82
|
|
|
$this->appIO, |
83
|
|
|
$composerConfig->get('cache-files-dir'), |
84
|
|
|
'a-z0-9_./' |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$fileDownloader = new \Composer\Downloader\FileDownloader($this->appIO, $composerConfig, null, $cache); |
89
|
|
|
|
90
|
|
|
$vendorRoot = $composerConfig->get(\Vaimo\ComposerPatches\Composer\ConfigKeys::VENDOR_DIR); |
91
|
|
|
|
92
|
|
|
$packageInfoResolver = new \Vaimo\ComposerPatches\Package\InfoResolver( |
93
|
|
|
$installationManager, |
94
|
|
|
$vendorRoot |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$configExtractor = new \Vaimo\ComposerPatches\Package\ConfigExtractors\VendorConfigExtractor( |
98
|
|
|
$packageInfoResolver |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$platformPackages = $this->resolveConstraintPackages($composerConfig); |
102
|
|
|
|
103
|
|
|
$packageResolver = new \Vaimo\ComposerPatches\Composer\Plugin\PackageResolver( |
104
|
|
|
array($this->composer->getPackage()) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$repositoryManager = $this->composer->getRepositoryManager(); |
108
|
|
|
|
109
|
|
|
$pluginPackage = $packageResolver->resolveForNamespace( |
110
|
|
|
$repositoryManager->getLocalRepository(), |
111
|
|
|
__NAMESPACE__ |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$consoleSilencer = new \Vaimo\ComposerPatches\Console\Silencer($this->appIO); |
115
|
|
|
|
116
|
|
|
$defaults = array( |
117
|
|
|
'bundle' => new LoaderComponents\BundleComponent($rootPackage), |
118
|
|
|
'global-exclude' => $excludes ? new LoaderComponents\GlobalExcludeComponent($excludes) : false, |
119
|
|
|
'local-exclude' => new LoaderComponents\LocalExcludeComponent(), |
120
|
|
|
'root-patch' => new LoaderComponents\RootPatchComponent($rootPackage), |
121
|
|
|
'path-normalizer' => new LoaderComponents\PathNormalizerComponent($packageInfoResolver), |
122
|
|
|
'platform' => new LoaderComponents\PlatformComponent($platformPackages), |
123
|
|
|
'constraints' => new LoaderComponents\ConstraintsComponent($configExtractor), |
124
|
|
|
'downloader' => new LoaderComponents\DownloaderComponent( |
125
|
|
|
$pluginPackage, |
126
|
|
|
$fileDownloader, |
127
|
|
|
$consoleSilencer, |
128
|
|
|
$vendorRoot, |
129
|
|
|
$this->gracefulMode |
130
|
|
|
), |
131
|
|
|
'validator' => new LoaderComponents\ValidatorComponent(), |
132
|
|
|
'targets-resolver' => new LoaderComponents\TargetsResolverComponent($packageInfoResolver), |
133
|
|
|
'merger' => new LoaderComponents\MergerComponent(), |
134
|
|
|
'sorter' => new LoaderComponents\SorterComponent() |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
return array_values( |
138
|
|
|
array_filter( |
139
|
|
|
array_replace($defaults, $this->components) |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
private function resolveConstraintPackages(\Composer\Config $composerConfig) |
145
|
|
|
{ |
146
|
|
|
$platformOverrides = array_filter( |
147
|
|
|
(array)$composerConfig->get('platform') |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
if (!empty($platformOverrides)) { |
151
|
|
|
$platformOverrides = array(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$platformRepo = new \Composer\Repository\PlatformRepository( |
155
|
|
|
array(), |
156
|
|
|
$platformOverrides ? $platformOverrides : array() |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$platformPackages = array(); |
160
|
|
|
|
161
|
|
|
foreach ($platformRepo->getPackages() as $package) { |
162
|
|
|
$platformPackages[$package->getName()] = $package; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $platformPackages; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function registerComponent($name, $instance) |
169
|
|
|
{ |
170
|
|
|
$this->components[$name] = $instance; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|