1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
5
|
|
|
*/ |
6
|
|
|
namespace Vaimo\ComposerPatches; |
7
|
|
|
|
8
|
|
|
use Vaimo\ComposerPatches\Config as PluginConfig; |
9
|
|
|
use Vaimo\ComposerPatches\Factories; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
13
|
|
|
*/ |
14
|
|
|
class Bootstrap |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Vaimo\ComposerPatches\Composer\Context |
18
|
|
|
*/ |
19
|
|
|
private $composerContext; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Vaimo\ComposerPatches\Factories\ConfigFactory |
23
|
|
|
*/ |
24
|
|
|
private $configFactory; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Vaimo\ComposerPatches\Factories\PatchesLoaderFactory |
28
|
|
|
*/ |
29
|
|
|
private $loaderFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Vaimo\ComposerPatches\Factories\PatchesApplierFactory |
33
|
|
|
*/ |
34
|
|
|
private $applierFactory; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \Vaimo\ComposerPatches\Repository\Processor |
38
|
|
|
*/ |
39
|
|
|
private $repositoryProcessor; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool |
43
|
|
|
*/ |
44
|
|
|
private $loaderComponents; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var \Vaimo\ComposerPatches\Interfaces\ListResolverInterface |
48
|
|
|
*/ |
49
|
|
|
private $listResolver; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \Vaimo\ComposerPatches\Strategies\OutputStrategy |
53
|
|
|
*/ |
54
|
|
|
private $outputStrategy; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param \Vaimo\ComposerPatches\Composer\Context $composerContext |
58
|
|
|
* @param \Composer\IO\IOInterface $appIO |
59
|
|
|
* @param \Vaimo\ComposerPatches\Factories\ConfigFactory $configFactory |
60
|
|
|
* @param \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $listResolver |
61
|
|
|
* @param \Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy |
62
|
|
|
*/ |
63
|
|
|
public function __construct( |
64
|
|
|
\Vaimo\ComposerPatches\Composer\Context $composerContext, |
65
|
|
|
\Composer\IO\IOInterface $appIO, |
66
|
|
|
\Vaimo\ComposerPatches\Factories\ConfigFactory $configFactory, |
67
|
|
|
?\Vaimo\ComposerPatches\Interfaces\ListResolverInterface $listResolver = null, |
68
|
|
|
?\Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy = null |
69
|
|
|
) { |
70
|
|
|
$this->composerContext = $composerContext; |
71
|
|
|
$this->listResolver = $listResolver; |
72
|
|
|
$this->outputStrategy = $outputStrategy; |
73
|
|
|
|
74
|
|
|
$this->configFactory = $configFactory; |
75
|
|
|
|
76
|
|
|
$logger = new \Vaimo\ComposerPatches\Logger($appIO); |
77
|
|
|
|
78
|
|
|
$this->loaderComponents = new \Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool( |
79
|
|
|
$composerContext, |
80
|
|
|
$appIO |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$composer = $this->composerContext->getLocalComposer(); |
84
|
|
|
$this->loaderFactory = new Factories\PatchesLoaderFactory($composer); |
85
|
|
|
$this->applierFactory = new Factories\PatchesApplierFactory($composer, $logger); |
86
|
|
|
|
87
|
|
|
$this->repositoryProcessor = new \Vaimo\ComposerPatches\Repository\Processor($logger); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function applyPatches($devMode = false) |
91
|
|
|
{ |
92
|
|
|
return $this->applyPatchesWithConfig( |
93
|
|
|
$this->configFactory->create(), |
94
|
|
|
$devMode |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function stripPatches($devMode = false) |
99
|
|
|
{ |
100
|
|
|
$configSources = array( |
101
|
|
|
array(\Vaimo\ComposerPatches\Config::PATCHER_SOURCES => false) |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->applyPatchesWithConfig( |
105
|
|
|
$this->configFactory->create($configSources), |
106
|
|
|
$devMode |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
private function applyPatchesWithConfig(PluginConfig $config, $devMode = false) |
111
|
|
|
{ |
112
|
|
|
$composer = $this->composerContext->getLocalComposer(); |
113
|
|
|
$repository = $composer->getRepositoryManager()->getLocalRepository(); |
114
|
|
|
|
115
|
|
|
$patchesLoader = $this->loaderFactory->create($this->loaderComponents, $config, $devMode); |
116
|
|
|
|
117
|
|
|
$patchesApplier = $this->applierFactory->create( |
118
|
|
|
$config, |
119
|
|
|
$this->listResolver, |
120
|
|
|
$this->outputStrategy |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
return $this->repositoryProcessor->process($repository, $patchesLoader, $patchesApplier); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|