-
Notifications
You must be signed in to change notification settings - Fork 8
/
HordeInstallerPlugin.php
109 lines (98 loc) · 2.89 KB
/
HordeInstallerPlugin.php
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
<?php
declare(strict_types = 1);
namespace Horde\Composer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Installer\PackageEvent;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Plugin\Capable;
class HordeInstallerPlugin implements PluginInterface, EventSubscriberInterface, Capable
{
protected HordeInstaller $installer;
public function activate(Composer $composer, IOInterface $io): void
{
$this->installer = new HordeInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($this->installer);
}
public function deactivate(Composer $composer, IOInterface $io): void
{
$composer->getInstallationManager()->removeInstaller($this->installer);
}
public function uninstall(Composer $composer, IOInterface $io): void
{
return;
}
/**
* Exposre which events are handled by which handler
*
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
'post-package-install' => 'postInstallHandler',
'post-package-update' => 'postUpdateHandler',
];
}
/**
* Handler for post-package-install
*
* @param PackageEvent $event
* @return void
*/
public function postInstallHandler(PackageEvent $event): void
{
$ops = $event->getOperations();
foreach($ops as $op) {
if ($op instanceof InstallOperation) {
$package = $op->getPackage();
try {
$this->installer->postinstall($package);
} catch (\Exception $e) {
}
}
}
}
/**
* Handler for post-package-update
*
* @param PackageEvent $event
* @return void
*/
public function postUpdateHandler(PackageEvent $event): void
{
$ops = $event->getOperations();
foreach($ops as $op) {
if ($op instanceof UpdateOperation) {
$package = $op->getTargetPackage();
try {
$this->installer->postinstall($package);
} catch (\Exception $e) {
}
}
}
}
/**
* Expose capabilities
*
* @return string[]
*/
public function getCapabilities(): array
{
return [
'Composer\Plugin\Capability\CommandProvider' => 'Horde\Composer\CommandProvider',
];
}
public function deactivate(Composer $composer, IOInterface $io)
{
$installer = new HordeInstaller($io, $composer);
$composer->getInstallationManager()->removeInstaller($installer);
}
public function uninstall(Composer $composer, IOInterface $io)
{
return;
}
}