-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathPlugin.php
More file actions
154 lines (124 loc) · 4.61 KB
/
Copy pathPlugin.php
File metadata and controls
154 lines (124 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* Copyright © Vaimo Group. All rights reserved.
* See LICENSE_VAIMO.txt for license details.
*/
namespace Vaimo\ComposerPatches;
use Composer\EventDispatcher\ScriptExecutionException;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Plugin implements
\Composer\Plugin\PluginInterface,
\Composer\EventDispatcher\EventSubscriberInterface,
\Composer\Plugin\Capable
{
const COMPOSER_PACKAGE = 'vaimo/composer-patches';
/**
* @var \Vaimo\ComposerPatches\Package\OperationAnalyser
*/
private $operationAnalyser;
/**
* @var \Vaimo\ComposerPatches\Strategies\BootstrapStrategy
*/
private $bootstrapStrategy;
/**
* @var \Vaimo\ComposerPatches\Factories\BootstrapFactory
*/
private $bootstrapFactory;
/**
* @var \Vaimo\ComposerPatches\Bootstrap
*/
private $bootstrap;
/**
* @var \Vaimo\ComposerPatches\Repository\Lock\Sanitizer
*/
private $lockSanitizer;
/**
* @var string[]
*/
private $capabilitiesConfig = array();
public function activate(\Composer\Composer $composer, \Composer\IO\IOInterface $appIO)
{
$contextFactory = new \Vaimo\ComposerPatches\Factories\ComposerContextFactory($composer);
$composerContext = $contextFactory->create();
$this->operationAnalyser = new \Vaimo\ComposerPatches\Package\OperationAnalyser();
$this->bootstrapFactory = new \Vaimo\ComposerPatches\Factories\BootstrapFactory($composerContext, $appIO);
$this->lockSanitizer = new \Vaimo\ComposerPatches\Repository\Lock\Sanitizer($appIO);
$this->bootstrapStrategy = new \Vaimo\ComposerPatches\Strategies\BootstrapStrategy($composerContext);
$this->bootstrap = $this->bootstrapFactory->create();
$pluginBootstrap = new \Vaimo\ComposerPatches\Composer\Plugin\Bootstrap($composer, $composerContext);
$pluginBootstrap->preloadPluginClasses();
if (!interface_exists('\Composer\Plugin\Capability\CommandProvider')
|| !$this->bootstrapStrategy->shouldAllow()
) {
return;
}
$this->capabilitiesConfig = array(
'Composer\Plugin\Capability\CommandProvider' => '\Vaimo\ComposerPatches\Composer\CommandsProvider',
);
}
public function getCapabilities()
{
return $this->capabilitiesConfig;
}
public static function getSubscribedEvents()
{
return array(
\Composer\Script\ScriptEvents::PRE_AUTOLOAD_DUMP => 'postInstall',
\Composer\Installer\PackageEvents::PRE_PACKAGE_UNINSTALL => 'resetPackages'
);
}
public function postInstall(\Composer\Script\Event $event)
{
if (!$this->bootstrap) {
$this->lockSanitizer->sanitize();
return;
}
if (!$this->bootstrapStrategy->shouldAllow()) {
$this->lockSanitizer->sanitize();
return;
}
$runtimeUtils = new \Vaimo\ComposerPatches\Utils\RuntimeUtils();
$compExecutor = new \Vaimo\ComposerPatches\Compatibility\Executor();
$lockSanitizer = $this->lockSanitizer;
$bootstrap = $this->bootstrap;
$result = $runtimeUtils->executeWithPostAction(
function () use ($bootstrap, $event) {
return $bootstrap->applyPatches($event->isDevMode());
},
function () use ($event, $lockSanitizer, $compExecutor) {
$repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
$installationManager = $event->getComposer()->getInstallationManager();
$compExecutor->repositoryWrite($repository, $installationManager, $event->isDevMode());
$lockSanitizer->sanitize();
}
);
if ($result) {
return;
}
throw new ScriptExecutionException('Execution halted due to composer-patch failure', 1);
}
public function resetPackages(\Composer\Installer\PackageEvent $event)
{
if (!$this->operationAnalyser->isPatcherUninstallOperation($event->getOperation())) {
return;
}
if (!getenv(\Vaimo\ComposerPatches\Environment::SKIP_CLEANUP)) {
$this->bootstrap->stripPatches();
}
$this->bootstrap = null;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function deactivate(\Composer\Composer $composer, \Composer\IO\IOInterface $appIO)
{
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function uninstall(\Composer\Composer $composer, \Composer\IO\IOInterface $appIO)
{
}
}