Plugin.php
2.5 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
<?php
declare(strict_types=1);
/*
* This file is part of the EasyWeChatComposer.
*
* (c) 张铭阳 <mingyoungcheung@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace EasyWeChatComposer;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
class Plugin implements PluginInterface, EventSubscriberInterface, Capable
{
/**
* @var bool
*/
protected $activated = true;
/**
* Apply plugin modifications to Composer.
*/
public function activate(Composer $composer, IOInterface $io)
{
//
}
/**
* Remove any hooks from Composer.
*
* This will be called when a plugin is deactivated before being
* uninstalled, but also before it gets upgraded to a new version
* so the old one can be deactivated and the new one activated.
*/
public function deactivate(Composer $composer, IOInterface $io)
{
//
}
/**
* Prepare the plugin to be uninstalled.
*
* This will be called after deactivate.
*/
public function uninstall(Composer $composer, IOInterface $io)
{
}
/**
* @return array
*/
public function getCapabilities()
{
return [
'Composer\Plugin\Capability\CommandProvider' => 'EasyWeChatComposer\Commands\Provider',
];
}
/**
* Listen events.
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
PackageEvents::PRE_PACKAGE_UNINSTALL => 'prePackageUninstall',
ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump',
];
}
/**
* @param \Composer\Installer\PackageEvent
*/
public function prePackageUninstall(PackageEvent $event)
{
if ($event->getOperation()->getPackage()->getName() === 'overtrue/wechat') {
$this->activated = false;
}
}
public function postAutoloadDump(Event $event)
{
if (!$this->activated) {
return;
}
$manifest = new ManifestManager(
rtrim($event->getComposer()->getConfig()->get('vendor-dir'), '/')
);
$manifest->unlink()->build();
}
}