mingyoung /
easywechat-composer
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the EasyWeChatComposer. |
||
| 7 | * |
||
| 8 | * (c) 张铭阳 <[email protected]> |
||
| 9 | * |
||
| 10 | * This source file is subject to the MIT license that is bundled |
||
| 11 | * with this source code in the file LICENSE. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace EasyWeChatComposer; |
||
| 15 | |||
| 16 | use Composer\Composer; |
||
| 17 | use Composer\EventDispatcher\EventSubscriberInterface; |
||
| 18 | use Composer\Installer\PackageEvent; |
||
| 19 | use Composer\Installer\PackageEvents; |
||
| 20 | use Composer\IO\IOInterface; |
||
| 21 | use Composer\Plugin\Capable; |
||
| 22 | use Composer\Plugin\PluginInterface; |
||
| 23 | use Composer\Script\Event; |
||
| 24 | use Composer\Script\ScriptEvents; |
||
| 25 | |||
| 26 | class Plugin implements PluginInterface, EventSubscriberInterface, Capable |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var bool |
||
| 30 | */ |
||
| 31 | protected $activated = true; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Apply plugin modifications to Composer. |
||
| 35 | */ |
||
| 36 | public function activate(Composer $composer, IOInterface $io) |
||
| 37 | { |
||
| 38 | // |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Remove any hooks from Composer. |
||
| 43 | * |
||
| 44 | * This will be called when a plugin is deactivated before being |
||
| 45 | * uninstalled, but also before it gets upgraded to a new version |
||
| 46 | * so the old one can be deactivated and the new one activated. |
||
| 47 | */ |
||
| 48 | public function deactivate(Composer $composer, IOInterface $io) |
||
| 49 | { |
||
| 50 | // |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Prepare the plugin to be uninstalled. |
||
| 55 | * |
||
| 56 | * This will be called after deactivate. |
||
| 57 | */ |
||
| 58 | public function uninstall(Composer $composer, IOInterface $io) |
||
| 59 | { |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | public function getCapabilities() |
||
| 66 | { |
||
| 67 | return [ |
||
| 68 | 'Composer\Plugin\Capability\CommandProvider' => 'EasyWeChatComposer\Commands\Provider', |
||
| 69 | ]; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Listen events. |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public static function getSubscribedEvents() |
||
| 78 | { |
||
| 79 | return [ |
||
| 80 | PackageEvents::PRE_PACKAGE_UNINSTALL => 'prePackageUninstall', |
||
| 81 | ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump', |
||
| 82 | ]; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param \Composer\Installer\PackageEvent |
||
| 87 | */ |
||
| 88 | public function prePackageUninstall(PackageEvent $event) |
||
| 89 | { |
||
| 90 | if ($event->getOperation()->getPackage()->getName() === 'overtrue/wechat') { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 91 | $this->activated = false; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | public function postAutoloadDump(Event $event) |
||
| 96 | { |
||
| 97 | if (!$this->activated) { |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | $manifest = new ManifestManager( |
||
| 102 | rtrim($event->getComposer()->getConfig()->get('vendor-dir'), '/') |
||
| 103 | ); |
||
| 104 | |||
| 105 | $manifest->unlink()->build(); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |