From aeafe2fe59992efd1bc3f890b760f1a9c4874e1c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 22 Apr 2016 20:30:24 +0100 Subject: [PATCH] Add INIT event and bump plugin-api to 1.1.0, fixes #5232 --- doc/articles/scripts.md | 2 ++ src/Composer/Factory.php | 19 +++++++++++++------ src/Composer/Plugin/PluginEvents.php | 10 ++++++++++ src/Composer/Plugin/PluginInterface.php | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/doc/articles/scripts.md b/doc/articles/scripts.md index 97b433bfa..415d56f63 100644 --- a/doc/articles/scripts.md +++ b/doc/articles/scripts.md @@ -54,6 +54,7 @@ Composer fires the following named events during its execution process: ### Plugin Events +- **init**: occurs after a Composer instance is done being initialized. - **command**: occurs before any Composer Command is executed on the CLI. It provides you with access to the input and output objects of the program. - **pre-file-download**: occurs before files are downloaded and allows @@ -162,6 +163,7 @@ objects: - Installer Events: [`Composer\Installer\InstallerEvent`](https://getcomposer.org/apidoc/master/Composer/Installer/InstallerEvent.html) - Package Events: [`Composer\Installer\PackageEvent`](https://getcomposer.org/apidoc/master/Composer/Installer/PackageEvent.html) - Plugin Events: + - init: [`Composer\EventDispatcher\Event`](https://getcomposer.org/apidoc/master/Composer/EventDispatcher/Event.html) - command: [`Composer\Plugin\CommandEvent`](https://getcomposer.org/apidoc/master/Composer/Plugin/CommandEvent.html) - pre-file-download: [`Composer\Plugin\PreFileDownloadEvent`](https://getcomposer.org/apidoc/master/Composer/Plugin/PreFileDownloadEvent.html) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index c05a57036..84c6a6e76 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -25,6 +25,8 @@ use Composer\Util\Platform; use Composer\Util\ProcessExecutor; use Composer\Util\RemoteFilesystem; use Composer\Util\Silencer; +use Composer\Plugin\PluginEvents; +use Composer\EventDispatcher\Event; use Seld\JsonLint\DuplicateKeyException; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Composer\EventDispatcher\EventDispatcher; @@ -353,12 +355,6 @@ class Factory $composer->setPluginManager($pm); $pm->loadInstalledPlugins(); - - // once we have plugins and custom installers we can - // purge packages from local repos if they have been deleted on the filesystem - if ($rm->getLocalRepository()) { - $this->purgePackages($rm->getLocalRepository(), $im); - } } // init locker if possible @@ -371,6 +367,17 @@ class Factory $composer->setLocker($locker); } + if ($fullLoad) { + $initEvent = new Event(PluginEvents::INIT); + $composer->getEventDispatcher()->dispatch($initEvent->getName(), $initEvent); + + // once everything is initialized we can + // purge packages from local repos if they have been deleted on the filesystem + if ($rm->getLocalRepository()) { + $this->purgePackages($rm->getLocalRepository(), $im); + } + } + return $composer; } diff --git a/src/Composer/Plugin/PluginEvents.php b/src/Composer/Plugin/PluginEvents.php index ce9efdef2..0304ebb9a 100644 --- a/src/Composer/Plugin/PluginEvents.php +++ b/src/Composer/Plugin/PluginEvents.php @@ -19,6 +19,16 @@ namespace Composer\Plugin; */ class PluginEvents { + /** + * The INIT event occurs after a Composer instance is done being initialized + * + * The event listener method receives a + * Composer\EventDispatcher\Event instance. + * + * @var string + */ + const INIT = 'init'; + /** * The COMMAND event occurs as a command begins * diff --git a/src/Composer/Plugin/PluginInterface.php b/src/Composer/Plugin/PluginInterface.php index a8c2b6a94..6eaca4e90 100644 --- a/src/Composer/Plugin/PluginInterface.php +++ b/src/Composer/Plugin/PluginInterface.php @@ -27,7 +27,7 @@ interface PluginInterface * * @var string */ - const PLUGIN_API_VERSION = '1.0.0'; + const PLUGIN_API_VERSION = '1.1.0'; /** * Apply plugin modifications to Composer