1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
5
|
|
|
*/ |
6
|
|
|
namespace Vaimo\ComposerPatches\Factories; |
7
|
|
|
|
8
|
|
|
use Vaimo\ComposerPatches\Config as PluginConfig; |
9
|
|
|
use Vaimo\ComposerPatches\Patch; |
10
|
|
|
use Vaimo\ComposerPatches\Patch\Definition\ExploderComponents; |
11
|
|
|
use Vaimo\ComposerPatches\Patch\Definition\NormalizerComponents; |
12
|
|
|
use Vaimo\ComposerPatches\Patch\SourceLoaders; |
13
|
|
|
use Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool as LoaderComponents; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
17
|
|
|
*/ |
18
|
|
|
class PatchesLoaderFactory |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \Composer\Composer |
22
|
|
|
*/ |
23
|
|
|
private $composer; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param \Composer\Composer $composer |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
\Composer\Composer $composer |
30
|
|
|
) { |
31
|
|
|
$this->composer = $composer; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
36
|
|
|
* |
37
|
|
|
* @param LoaderComponents $loaderComponentsPool |
38
|
|
|
* @param PluginConfig $pluginConfig |
39
|
|
|
* @param bool $devMode |
40
|
|
|
* @return Patch\DefinitionList\Loader |
41
|
|
|
*/ |
42
|
|
|
public function create(LoaderComponents $loaderComponentsPool, PluginConfig $pluginConfig, $devMode = false) |
43
|
|
|
{ |
44
|
|
|
$installationManager = $this->composer->getInstallationManager(); |
45
|
|
|
|
46
|
|
|
$rootPackage = $this->composer->getPackage(); |
47
|
|
|
|
48
|
|
|
$loaders = array( |
49
|
|
|
PluginConfig::DEFINITIONS_LIST => new SourceLoaders\PatchList(), |
50
|
|
|
PluginConfig::DEFINITIONS_FILE => new SourceLoaders\PatchesFile($installationManager), |
51
|
|
|
PluginConfig::DEFINITIONS_SEARCH => new SourceLoaders\PatchesSearch( |
52
|
|
|
$installationManager, |
53
|
|
|
$devMode |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
if ($devMode) { |
58
|
|
|
$loaders = array_replace($loaders, array( |
59
|
|
|
PluginConfig::DEV_DEFINITIONS_LIST => $loaders[PluginConfig::DEFINITIONS_LIST], |
60
|
|
|
PluginConfig::DEV_DEFINITIONS_FILE => $loaders[PluginConfig::DEFINITIONS_FILE] |
61
|
|
|
)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$exploderComponents = array( |
65
|
|
|
new ExploderComponents\LabelVersionConfigComponent(), |
66
|
|
|
new ExploderComponents\VersionConfigComponent(), |
67
|
|
|
new ExploderComponents\VersionRangesConfigComponent(), |
68
|
|
|
new ExploderComponents\ComplexItemComponent(), |
69
|
|
|
new ExploderComponents\SequenceVersionConfigComponent(), |
70
|
|
|
new ExploderComponents\SequenceItemComponent(), |
71
|
|
|
new ExploderComponents\GroupVersionConfigComponent() |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$definitionExploder = new Patch\Definition\Exploder($exploderComponents); |
75
|
|
|
|
76
|
|
|
$normalizerComponents = array( |
77
|
|
|
new NormalizerComponents\DefaultValuesComponent(), |
78
|
|
|
new NormalizerComponents\BaseComponent(), |
79
|
|
|
new NormalizerComponents\DependencyComponent(), |
80
|
|
|
new NormalizerComponents\PathComponent(), |
81
|
|
|
new NormalizerComponents\BasePathComponent(), |
82
|
|
|
new NormalizerComponents\UrlComponent(), |
83
|
|
|
new NormalizerComponents\SkipComponent(), |
84
|
|
|
new NormalizerComponents\SequenceComponent(), |
85
|
|
|
new NormalizerComponents\PatcherConfigComponent() |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$definitionNormalizer = new Patch\Definition\Normalizer($normalizerComponents); |
89
|
|
|
|
90
|
|
|
$listNormalizer = new Patch\ListNormalizer( |
91
|
|
|
$definitionExploder, |
92
|
|
|
$definitionNormalizer |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$configReaderFactory = new \Vaimo\ComposerPatches\Factories\PatcherConfigReaderFactory( |
96
|
|
|
$this->composer |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$configReader = $configReaderFactory->create($pluginConfig); |
100
|
|
|
|
101
|
|
|
$patchesCollector = new Patch\Collector( |
102
|
|
|
$listNormalizer, |
103
|
|
|
$configReader, |
104
|
|
|
$loaders |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$loaderComponents = $loaderComponentsPool->getList($pluginConfig); |
108
|
|
|
|
109
|
|
|
$srcResolverFactory = new \Vaimo\ComposerPatches\Factories\SourcesResolverFactory( |
110
|
|
|
$this->composer |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
return new \Vaimo\ComposerPatches\Patch\DefinitionList\Loader( |
114
|
|
|
new \Vaimo\ComposerPatches\Package\Collector( |
115
|
|
|
array($rootPackage) |
116
|
|
|
), |
117
|
|
|
$patchesCollector, |
118
|
|
|
$srcResolverFactory->create($pluginConfig), |
119
|
|
|
$loaderComponents |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|