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
|
|
|
use Vaimo\ComposerPatches\Config as PluginConfig; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
13
|
|
|
*/ |
14
|
|
|
class ComponentPool |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Vaimo\ComposerPatches\Composer\Context |
18
|
|
|
*/ |
19
|
|
|
private $composerContext; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Composer\IO\IOInterface |
23
|
|
|
*/ |
24
|
|
|
private $appIO; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var bool[]|\Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface[] |
28
|
|
|
*/ |
29
|
|
|
private $components = array(); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $gracefulMode; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
38
|
|
|
* |
39
|
|
|
* @param \Vaimo\ComposerPatches\Composer\Context $composerContext |
40
|
|
|
* @param \Composer\IO\IOInterface $appIO |
41
|
|
|
* @param bool $gracefulMode |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
\Vaimo\ComposerPatches\Composer\Context $composerContext, |
45
|
|
|
\Composer\IO\IOInterface $appIO, |
46
|
|
|
$gracefulMode = false |
47
|
|
|
) { |
48
|
|
|
$this->composerContext = $composerContext; |
49
|
|
|
$this->appIO = $appIO; |
50
|
|
|
$this->gracefulMode = $gracefulMode; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
55
|
|
|
*/ |
56
|
|
|
public function getList(PluginConfig $pluginConfig) |
57
|
|
|
{ |
58
|
|
|
$patcherConfig = $pluginConfig->getPatcherConfig(); |
59
|
|
|
$composer = $this->composerContext->getLocalComposer(); |
60
|
|
|
$composerConfig = clone $composer->getConfig(); |
61
|
|
|
|
62
|
|
|
$composerConfig->merge(array( |
63
|
|
|
'config' => array('secure-http' => $patcherConfig[PluginConfig::PATCHER_SECURE_HTTP]) |
64
|
|
|
)); |
65
|
|
|
|
66
|
|
|
$rootPackage = $composer->getPackage(); |
67
|
|
|
$extra = $rootPackage->getExtra(); |
68
|
|
|
|
69
|
|
|
if (isset($extra['excluded-patches']) && !isset($extra[PluginConfig::EXCLUDED_PATCHES])) { |
70
|
|
|
$extra[PluginConfig::EXCLUDED_PATCHES] = $extra['excluded-patches']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$excludes = isset($extra[PluginConfig::EXCLUDED_PATCHES]) |
74
|
|
|
? $extra[PluginConfig::EXCLUDED_PATCHES] |
75
|
|
|
: array(); |
76
|
|
|
|
77
|
|
|
$installationManager = $composer->getInstallationManager(); |
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
|
|
|
$composerDependencies = new \Vaimo\ComposerPatches\Compatibility\DependenciesFactory(); |
89
|
|
|
$fileDownloader = $composerDependencies->createFileDownloader( |
90
|
|
|
$this->appIO, |
91
|
|
|
$composer, |
92
|
|
|
$composerConfig, |
93
|
|
|
$cache |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$vendorRoot = $composerConfig->get(\Vaimo\ComposerPatches\Composer\ConfigKeys::VENDOR_DIR); |
97
|
|
|
$packageInfoResolver = new \Vaimo\ComposerPatches\Package\InfoResolver( |
98
|
|
|
$installationManager, |
99
|
|
|
$vendorRoot |
100
|
|
|
); |
101
|
|
|
$configExtractor = new \Vaimo\ComposerPatches\Package\ConfigExtractors\VendorConfigExtractor( |
102
|
|
|
$packageInfoResolver |
103
|
|
|
); |
104
|
|
|
$composerConfigUtils = new \Vaimo\ComposerPatches\Utils\ComposerConfigUtils(); |
105
|
|
|
$platformPackages = $composerConfigUtils->resolveConstraintPackages($composerConfig); |
106
|
|
|
$packageResolver = new \Vaimo\ComposerPatches\Composer\Plugin\PackageResolver( |
107
|
|
|
array($composer->getPackage()) |
108
|
|
|
); |
109
|
|
|
$packages = $this->composerContext->getActivePackages(); |
110
|
|
|
$pluginPackage = $packageResolver->resolveForNamespace($packages, __NAMESPACE__); |
111
|
|
|
$consoleSilencer = new \Vaimo\ComposerPatches\Console\Silencer($this->appIO); |
112
|
|
|
|
113
|
|
|
$defaults = array( |
114
|
|
|
'bundle' => new LoaderComponents\BundleComponent($rootPackage), |
115
|
|
|
'global-exclude' => $excludes ? new LoaderComponents\GlobalExcludeComponent($excludes) : false, |
116
|
|
|
'local-exclude' => new LoaderComponents\LocalExcludeComponent(), |
117
|
|
|
'root-patch' => new LoaderComponents\RootPatchComponent($rootPackage), |
118
|
|
|
'path-normalizer' => new LoaderComponents\PathNormalizerComponent($packageInfoResolver), |
119
|
|
|
'platform' => new LoaderComponents\PlatformComponent($platformPackages), |
120
|
|
|
'constraints' => new LoaderComponents\ConstraintsComponent($configExtractor), |
121
|
|
|
'downloader' => new LoaderComponents\DownloaderComponent( |
122
|
|
|
$composer, |
123
|
|
|
$pluginPackage, |
124
|
|
|
$fileDownloader, |
125
|
|
|
$consoleSilencer, |
126
|
|
|
$vendorRoot, |
127
|
|
|
$this->gracefulMode |
128
|
|
|
), |
129
|
|
|
'validator' => new LoaderComponents\ValidatorComponent(), |
130
|
|
|
'targets-resolver' => new LoaderComponents\TargetsResolverComponent($packageInfoResolver), |
131
|
|
|
'merger' => new LoaderComponents\MergerComponent(), |
132
|
|
|
'sorter' => new LoaderComponents\SorterComponent() |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
return array_values( |
136
|
|
|
array_filter(array_replace($defaults, $this->components)) |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function registerComponent($name, $instance) |
141
|
|
|
{ |
142
|
|
|
$this->components[$name] = $instance; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|