diff --git a/composer.json b/composer.json index 86a5698..2f741b0 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "comodojo/comodojo-installer", + "name": "pmarcelli/comodojo-installer", "type": "composer-plugin", "license": "MIT", "description": "Modular installer for the Comodojo Project", @@ -27,13 +27,13 @@ "class": "Comodojo\\Installer\\Plugin" }, "require": { - "php": ">=5.6.0", - "composer-plugin-api": "^1.0", - "comodojo/foundation": "dev-master", - "symfony/yaml": "^3.0" + "php": "^7.3", + "composer-plugin-api": "^2.0", + "pmarcelli/foundation": "dev-foundation_u7320", + "symfony/yaml": "^5.3" }, "require-dev": { - "composer/composer": "^1.0", + "composer/composer": "^2.0", "phpunit/phpunit": "^4.0|^5.0", "scrutinizer/ocular": "^1.0" } diff --git a/src/Comodojo/Installer/Installer.php b/src/Comodojo/Installer/Installer.php index b2ab7b2..5d283c8 100644 --- a/src/Comodojo/Installer/Installer.php +++ b/src/Comodojo/Installer/Installer.php @@ -10,6 +10,7 @@ use \Comodojo\Exception\InstallerException; use \Comodojo\Installer\Components\InstallerDriverManager; use \Comodojo\Foundation\Utils\ArrayOps; +use React\Promise\PromiseInterface; /** * @package Comodojo Framework @@ -34,14 +35,14 @@ class Installer extends LibraryInstaller { protected $supported_packages; protected $drivers = []; - + public function __construct( IOInterface $io, Composer $composer, Configuration $configuration, InstallerConfiguration $installer_configuration ) { - + $this->supported_packages = $installer_configuration->getPackageTypes(); $extra = $installer_configuration->getPackageExtra(); @@ -63,15 +64,30 @@ public function supports($packageType) { return in_array($packageType, $this->supported_packages); } - + /** * {@inheritDoc} */ public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { + + $installPackage = function() use ($package) { + + $this->packageInstall($package); + + }; + + // Composer v2 return a promise + $promise = parent::install($repo, $package); - parent::install($repo, $package); + if ($promise instanceof PromiseInterface) { + + return $promise->then($installPackage); - $this->packageInstall($package); + } + + $installPackage(); + + return null; } @@ -80,10 +96,25 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa */ public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { - parent::update($repo, $initial, $target); + $updatePackage = function() use ($initial, $target) { + + $this->packageUpdate($initial, $target); + + }; + + // Composer v2 return a promise + $promise = parent::update($repo, $initial, $target); - $this->packageUpdate($initial, $target); + if ($promise instanceof PromiseInterface) { + + return $promise->then($updatePackage); + } + + $updatePackage(); + + return null; + } /** @@ -91,10 +122,25 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini */ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { - $this->packageUninstall($package); + $uninstallPackage = function() use ($package) { + + $this->packageUninstall($package); + + }; + + // Composer v2 return a promise + $promise = parent::uninstall($repo, $package); + + if ($promise instanceof PromiseInterface) { + + return $promise->then($uninstallPackage); + + } - parent::uninstall($repo, $package); + $uninstallPackage(); + return null; + } private function packageInstall($package) { diff --git a/src/Comodojo/Installer/Plugin.php b/src/Comodojo/Installer/Plugin.php index d7fb80e..f36fb71 100644 --- a/src/Comodojo/Installer/Plugin.php +++ b/src/Comodojo/Installer/Plugin.php @@ -32,7 +32,21 @@ class Plugin implements PluginInterface, EventSubscriberInterface { protected $comodojo_configuration; protected $comodojo_configuration_persistence; - + + /** + * {@inheritDoc} + */ + public function deactivate(Composer $composer, IOInterface $io){ + + } + + /** + * {@inheritDoc} + */ + public function uninstall(Composer $composer, IOInterface $io){ + + } + public function activate(Composer $composer, IOInterface $io) { // First, get current extra field and init a valid installer configuration @@ -56,10 +70,11 @@ public function activate(Composer $composer, IOInterface $io) { public static function getSubscribedEvents() { - return ['post-create-project-cmd' => 'startPostInstallScript']; - + return ['post-create-project-cmd' => 'startPostInstallScript']; + } + public function startPostInstallScript(Event $event) { $script = $this->installer_configuration->getPostInstallScript();