From 2285c516bfa11897709e7e73cbced79dda3bba10 Mon Sep 17 00:00:00 2001 From: c33s Date: Sun, 1 Nov 2020 20:37:53 +0100 Subject: [PATCH] refs: #233 --- composer.json | 4 ++-- src/Plugin.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 21691e1..48810f2 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ "require": { "php": "^5.3.2 || ^7.0", "ext-curl": "*", - "composer-plugin-api": "^1.0.0" + "composer-plugin-api": "^1.0.0 || ^2.0" }, "require-dev": { - "composer/composer": "1.0.0", + "composer/composer": "1.0.0 || ^2.0@dev", "phpunit/phpunit": "4.8.* || 5.7.* || ^6.3", "squizlabs/php_codesniffer": "^2.5" }, diff --git a/src/Plugin.php b/src/Plugin.php index 50a19ed..548dcfd 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -7,16 +7,18 @@ namespace Hirak\Prestissimo; use Composer\Composer; -use Composer\IO; +use Composer\IO\IOInterface; use Composer\Plugin as CPlugin; use Composer\EventDispatcher; use Composer\Installer; +use Composer\Plugin\PluginInterface; +use Composer\Semver\Comparator; class Plugin implements CPlugin\PluginInterface, EventDispatcher\EventSubscriberInterface { - /** @var IO\IOInterface */ + /** @var IOInterface */ private $io; /** @var Composer\Config */ @@ -49,8 +51,12 @@ class Plugin implements 'https' ); - public function activate(Composer $composer, IO\IOInterface $io) + public function activate(Composer $composer, IOInterface $io) { + if (self::isApiVersion2OrHigher()) { + return $this->disable(); + } + // @codeCoverageIgnoreStart // guard for self-update problem if (__CLASS__ !== 'Hirak\Prestissimo\Plugin') { @@ -104,6 +110,10 @@ class_exists(__NAMESPACE__ . '\\' . $class); public static function getSubscribedEvents() { + if (self::isApiVersion2OrHigher()) { + return array(); + } + return array( CPlugin\PluginEvents::PRE_FILE_DOWNLOAD => 'onPreFileDownload', Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array( @@ -189,4 +199,17 @@ public function isDisabled() { return $this->disabled; } + + public function deactivate(Composer $composer, IOInterface $io) + { + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } + + protected static function isApiVersion2OrHigher() + { + return Comparator::greaterThanOrEqualTo(PluginInterface::PLUGIN_API_VERSION, '2.0.0'); + } }