Skip to content

Commit

Permalink
Add INIT event and bump plugin-api to 1.1.0, fixes #5232
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Apr 22, 2016
1 parent b6680b6 commit aeafe2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/articles/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 13 additions & 6 deletions src/Composer/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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;
Expand Down Expand Up @@ -353,12 +355,6 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
$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
Expand All @@ -371,6 +367,17 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
$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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Composer/Plugin/PluginEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
*/
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
*
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Plugin/PluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aeafe2f

Please sign in to comment.