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

Added support for Composer 2 #3

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"require" : {
"php" : ">=5.3.2",
"composer-plugin-api": "~1.1.0"
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev" : {
"composer/composer" : "1.1.*@dev",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "0.2.0",
"version" : "0.2.1",
"repository" : {
"type": "git",
"url" : "https://github.com/devaloka/mu-plugin-installer.git"
Expand Down
33 changes: 29 additions & 4 deletions src/Installer/MuPluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use React\Promise\PromiseInterface;

/**
* Class MuPluginInstaller
Expand Down Expand Up @@ -238,9 +239,21 @@ protected function resolveInstallPath(array $paths, $name)
*/
protected function installCode(PackageInterface $package)
{
parent::installCode($package);
$muPluginInstaller = $this;

$this->installLoader($package);
$installLoader = function () use ($muPluginInstaller, $package) {
$muPluginInstaller->installLoader($package);
};

$promise = parent::installCode($package);

// Composer v2 might return a promise here
if ($promise instanceof PromiseInterface) {
return $promise->then($installLoader);
}

// If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)
$installLoader();
}

/**
Expand All @@ -261,9 +274,21 @@ protected function installLoader(PackageInterface $package)
*/
protected function removeCode(PackageInterface $package)
{
parent::removeCode($package);
$muPluginInstaller = $this;

$removeLoader = function () use ($muPluginInstaller, $package) {
$muPluginInstaller->removeLoader($package);
};

$promise = parent::removeCode($package);

// Composer v2 might return a promise here
if ($promise instanceof PromiseInterface) {
return $promise->then($removeLoader);
}

$this->removeLoader($package);
// If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)
$removeLoader();
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Installer/MuPluginInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@
*/
class MuPluginInstallerPlugin implements PluginInterface
{
private $installer;

/**
* {@inheritDoc}
*/
public function activate(Composer $composer, IOInterface $io)
{
$installer = new MuPluginInstaller($io, $composer);
$this->installer = new MuPluginInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($this->installer);
}

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

$composer->getInstallationManager()->addInstaller($installer);
public function uninstall(Composer $composer, IOInterface $io)
{
}
}