1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mediact\TestingSuite\Composer; |
4
|
|
|
|
5
|
|
|
use Composer\Composer; |
6
|
|
|
use Composer\EventDispatcher\EventSubscriberInterface; |
7
|
|
|
use Composer\IO\IOInterface; |
8
|
|
|
use Composer\Plugin\PluginInterface; |
9
|
|
|
use Mediact\TestingSuite\Composer\Installer\InstallerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @SuppressWarnings(PHPMD.ShortVariable) |
13
|
|
|
*/ |
14
|
|
|
class Plugin implements PluginInterface, EventSubscriberInterface |
15
|
|
|
{ |
16
|
|
|
/** @var InstallerInterface[] */ |
17
|
|
|
private $installers; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Constructor. |
21
|
|
|
* |
22
|
|
|
* @param InstallerInterface[] ...$installers |
23
|
|
|
*/ |
24
|
1 |
|
public function __construct(InstallerInterface ...$installers) |
25
|
|
|
{ |
26
|
1 |
|
$this->installers = $installers; |
27
|
1 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Apply plugin modifications to Composer. |
31
|
|
|
* |
32
|
|
|
* @param Composer $composer |
33
|
|
|
* @param IOInterface $io |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
1 |
|
public function activate(Composer $composer, IOInterface $io) |
38
|
|
|
{ |
39
|
1 |
|
$this->addInstallers( |
40
|
1 |
|
...include __DIR__ . '/installers.php' |
41
|
|
|
); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Remove any hooks from Composer. |
46
|
|
|
* |
47
|
|
|
* @param Composer $composer |
48
|
|
|
* @param IOInterface $io |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function deactivate(Composer $composer, IOInterface $io) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Prepare the plugin to be uninstalled |
58
|
|
|
* |
59
|
|
|
* @param Composer $composer |
60
|
|
|
* @param IOInterface $io |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function uninstall(Composer $composer, IOInterface $io) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Add installers. |
70
|
|
|
* |
71
|
|
|
* @param InstallerInterface[] ...$installers |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
1 |
|
public function addInstallers(InstallerInterface ...$installers) |
76
|
|
|
{ |
77
|
1 |
|
$this->installers = array_merge($this->installers, $installers); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Run the installers. |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
1 |
|
public function install() |
86
|
|
|
{ |
87
|
1 |
|
foreach ($this->installers as $installer) { |
88
|
1 |
|
$installer->install(); |
89
|
|
|
} |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Subscribe to post update and post install command. |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
1 |
|
public static function getSubscribedEvents(): array |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
1 |
|
'post-install-cmd' => [ |
101
|
|
|
'install' |
102
|
|
|
], |
103
|
|
|
'post-update-cmd' => [ |
104
|
|
|
'install' |
105
|
|
|
] |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.