Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: composer 2 compatibility #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
29 changes: 26 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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');
}
}