Skip to content

Commit

Permalink
Initial work on adding Composer 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 15, 2020
1 parent fbd2069 commit cd9d9ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"license": "MIT",
"minimum-stability": "stable",
"require": {
"composer-plugin-api": "^1.0"
"composer-plugin-api": "^1.0 || ^2.0"
},
"autoload": {
"psr-4": {
Expand Down
28 changes: 24 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,38 @@
*/
class Plugin implements PluginInterface
{
/**
* @var Installer
*/
private $installer;

/**
* @inheritdoc
*/
public function activate(Composer $composer, IOInterface $io)
{
// Register the plugin installer
$installer = new Installer($io, $composer, 'craft-plugin');
$composer->getInstallationManager()->addInstaller($installer);
$this->installer = new Installer($io, $composer, 'craft-plugin');
$composer->getInstallationManager()->addInstaller($this->installer);

// Is this a plugin at root? Elementary, my dear Watson 🕵️!
if ($installer->supports($composer->getPackage()->getType())) {
$installer->addPlugin($composer->getPackage(), true);
if ($this->installer->supports($composer->getPackage()->getType())) {
$this->installer->addPlugin($composer->getPackage(), true);
}
}

/**
* @inheritdoc
*/
public function deactivate(Composer $composer, IOInterface $io)
{
$composer->getInstallationManager()->removeInstaller($this->installer);
}

/**
* @inheritdoc
*/
public function uninstall(Composer $composer, IOInterface $io)
{
}
}

0 comments on commit cd9d9ae

Please sign in to comment.