Browse Source

Clean up event dispatching code and make package events extend installer events

Jordi Boggiano 10 years ago
parent
commit
3efed220a6

+ 2 - 2
src/Composer/Command/CreateProjectCommand.php

@@ -149,7 +149,7 @@ EOT
 
         if ($noScripts === false) {
             // dispatch event
-            $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
+            $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
         }
 
         $rootPackageConfig = $composer->getConfig();
@@ -217,7 +217,7 @@ EOT
 
         if ($noScripts === false) {
             // dispatch event
-            $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
+            $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
         }
 
         chdir($oldCwd);

+ 4 - 14
src/Composer/Command/RunScriptCommand.php

@@ -27,7 +27,7 @@ class RunScriptCommand extends Command
     /**
      * @var array Array with command events
      */
-    protected $commandEvents = array(
+    protected $scriptEvents = array(
         ScriptEvents::PRE_INSTALL_CMD,
         ScriptEvents::POST_INSTALL_CMD,
         ScriptEvents::PRE_UPDATE_CMD,
@@ -35,17 +35,11 @@ class RunScriptCommand extends Command
         ScriptEvents::PRE_STATUS_CMD,
         ScriptEvents::POST_STATUS_CMD,
         ScriptEvents::POST_ROOT_PACKAGE_INSTALL,
-        ScriptEvents::POST_CREATE_PROJECT_CMD
-    );
-
-    /**
-     * @var array Array with script events
-     */
-    protected $scriptEvents = array(
+        ScriptEvents::POST_CREATE_PROJECT_CMD,
         ScriptEvents::PRE_ARCHIVE_CMD,
         ScriptEvents::POST_ARCHIVE_CMD,
         ScriptEvents::PRE_AUTOLOAD_DUMP,
-        ScriptEvents::POST_AUTOLOAD_DUMP
+        ScriptEvents::POST_AUTOLOAD_DUMP,
     );
 
     protected function configure()
@@ -78,7 +72,7 @@ EOT
         }
 
         $script = $input->getArgument('script');
-        if (!in_array($script, $this->commandEvents) && !in_array($script, $this->scriptEvents)) {
+        if (!in_array($script, $this->scriptEvents)) {
             if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
                 throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
             }
@@ -98,10 +92,6 @@ EOT
 
         $args = $input->getArgument('args');
 
-        if (in_array($script, $this->commandEvents)) {
-            return $composer->getEventDispatcher()->dispatchCommandEvent($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args);
-        }
-
         return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args);
     }
 

+ 2 - 2
src/Composer/Command/StatusCommand.php

@@ -57,7 +57,7 @@ EOT
         $im = $composer->getInstallationManager();
 
         // Dispatch pre-status-command
-        $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::PRE_STATUS_CMD, true);
+        $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true);
 
         $errors = array();
 
@@ -98,7 +98,7 @@ EOT
         }
 
         // Dispatch post-status-command
-        $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_STATUS_CMD, true);
+        $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true);
 
         return $errors ? 1 : 0;
     }

+ 26 - 25
src/Composer/EventDispatcher/EventDispatcher.php

@@ -21,7 +21,6 @@ use Composer\Composer;
 use Composer\DependencyResolver\Operation\OperationInterface;
 use Composer\Repository\CompositeRepository;
 use Composer\Script;
-use Composer\Script\CommandEvent;
 use Composer\Script\PackageEvent;
 use Composer\Util\ProcessExecutor;
 
@@ -95,36 +94,28 @@ class EventDispatcher
     /**
      * Dispatch a package event.
      *
-     * @param  string             $eventName The constant in ScriptEvents
-     * @param  boolean            $devMode   Whether or not we are in dev mode
-     * @param  OperationInterface $operation The package being installed/updated/removed
-     * @return int                return code of the executed script if any, for php scripts a false return
-     *                                      value is changed to 1, anything else to 0
-     */
-    public function dispatchPackageEvent($eventName, $devMode, OperationInterface $operation)
-    {
-        return $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $operation));
-    }
-
-    /**
-     * Dispatch a command event.
+     * @param string              $eventName     The constant in PackageEvents
+     * @param bool                $devMode       Whether or not we are in dev mode
+     * @param PolicyInterface     $policy        The policy
+     * @param Pool                $pool          The pool
+     * @param CompositeRepository $installedRepo The installed repository
+     * @param Request             $request       The request
+     * @param array               $operations    The list of operations
+     * @param OperationInterface  $operation     The package being installed/updated/removed
      *
-     * @param  string  $eventName      The constant in ScriptEvents
-     * @param  boolean $devMode        Whether or not we are in dev mode
-     * @param  array   $additionalArgs Arguments passed by the user
-     * @param  array   $flags          Optional flags to pass data not as argument
-     * @return int     return code of the executed script if any, for php scripts a false return
-     *                                value is changed to 1, anything else to 0
+     * @return int return code of the executed script if any, for php scripts a false return
+     *             value is changed to 1, anything else to 0
      */
-    public function dispatchCommandEvent($eventName, $devMode, $additionalArgs = array(), $flags = array())
+    public function dispatchPackageEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
     {
-        return $this->doDispatch(new CommandEvent($eventName, $this->composer, $this->io, $devMode, $additionalArgs, $flags));
+        return $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations, $operation));
     }
 
     /**
      * Dispatch a installer event.
      *
      * @param string              $eventName     The constant in InstallerEvents
+     * @param bool                $devMode       Whether or not we are in dev mode
      * @param PolicyInterface     $policy        The policy
      * @param Pool                $pool          The pool
      * @param CompositeRepository $installedRepo The installed repository
@@ -134,9 +125,9 @@ class EventDispatcher
      * @return int return code of the executed script if any, for php scripts a false return
      *             value is changed to 1, anything else to 0
      */
-    public function dispatchInstallerEvent($eventName, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
+    public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
     {
-        return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $policy, $pool, $installedRepo, $request, $operations));
+        return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations));
     }
 
     /**
@@ -232,8 +223,18 @@ class EventDispatcher
 
         $expected = $typehint->getName();
 
+        // BC support
         if (!$event instanceof $expected && $expected === 'Composer\Script\CommandEvent') {
-            $event = new CommandEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments());
+            $event = new \Composer\Script\CommandEvent(
+                $event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments()
+            );
+        }
+        if (!$event instanceof $expected && $expected === 'Composer\Script\PackageEvent') {
+            $event = new \Composer\Script\PackageEvent(
+                $event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(),
+                $event->getPolicy(), $event->getPool(), $event->getInstalledRepo(), $event->getRequest(),
+                $event->getOperations(), $event->getOperation()
+            );
         }
 
         return $event;

+ 10 - 10
src/Composer/Installer.php

@@ -192,7 +192,7 @@ class Installer
         if ($this->runScripts) {
             // dispatch pre event
             $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
-            $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
+            $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
         }
 
         $this->downloadManager->setPreferSource($this->preferSource);
@@ -289,10 +289,10 @@ class Installer
                         $request->install($link->getTarget(), $link->getConstraint());
                     }
 
-                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request);
+                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
                     $solver = new Solver($policy, $pool, $installedRepo);
                     $ops = $solver->solve($request, $this->ignorePlatformReqs);
-                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $ops);
+                    $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
                     foreach ($ops as $op) {
                         if ($op->getJobType() === 'uninstall') {
                             $devPackages[] = $op->getPackage();
@@ -334,7 +334,7 @@ class Installer
             if ($this->runScripts) {
                 // dispatch post event
                 $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
-                $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
+                $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
             }
 
             $vendorDir = $this->config->get('vendor-dir');
@@ -498,11 +498,11 @@ class Installer
         $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-links');
 
         // solve dependencies
-        $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request);
+        $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
         $solver = new Solver($policy, $pool, $installedRepo);
         try {
             $operations = $solver->solve($request, $this->ignorePlatformReqs);
-            $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $operations);
+            $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
         } catch (SolverProblemsException $e) {
             $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
             $this->io->write($e->getMessage());
@@ -562,9 +562,9 @@ class Installer
                 }
             }
 
-            $event = 'Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType());
+            $event = 'Composer\Installer\PackageEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType());
             if (defined($event) && $this->runScripts) {
-                $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
+                $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
             }
 
             // output non-alias ops in dry run, output alias ops in debug verbosity
@@ -595,9 +595,9 @@ class Installer
                 }
             }
 
-            $event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
+            $event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
             if (defined($event) && $this->runScripts) {
-                $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
+                $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
             }
 
             if (!$this->dryRun) {

+ 16 - 1
src/Composer/Installer/InstallerEvent.php

@@ -38,6 +38,11 @@ class InstallerEvent extends Event
      */
     private $io;
 
+    /**
+     * @var bool
+     */
+    private $devMode;
+
     /**
      * @var PolicyInterface
      */
@@ -69,18 +74,20 @@ class InstallerEvent extends Event
      * @param string               $eventName
      * @param Composer             $composer
      * @param IOInterface          $io
+     * @param bool                 $devMode
      * @param PolicyInterface      $policy
      * @param Pool                 $pool
      * @param CompositeRepository  $installedRepo
      * @param Request              $request
      * @param OperationInterface[] $operations
      */
-    public function __construct($eventName, Composer $composer, IOInterface $io, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
+    public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
     {
         parent::__construct($eventName);
 
         $this->composer = $composer;
         $this->io = $io;
+        $this->devMode = $devMode;
         $this->policy = $policy;
         $this->pool = $pool;
         $this->installedRepo = $installedRepo;
@@ -104,6 +111,14 @@ class InstallerEvent extends Event
         return $this->io;
     }
 
+    /**
+     * @return bool
+     */
+    public function isDevMode()
+    {
+        return $this->devMode;
+    }
+
     /**
      * @return PolicyInterface
      */

+ 69 - 0
src/Composer/Installer/PackageEvent.php

@@ -0,0 +1,69 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Installer;
+
+use Composer\Composer;
+use Composer\IO\IOInterface;
+use Composer\DependencyResolver\Operation\OperationInterface;
+
+/**
+ * The Package Event.
+ *
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class PackageEvent extends InstallerEvent
+{
+    /**
+     * @var OperationInterface The package instance
+     */
+    private $operation;
+
+    /**
+     * Constructor.
+     *
+     * @param string               $eventName
+     * @param Composer             $composer
+     * @param IOInterface          $io
+     * @param bool                 $devMode
+     * @param PolicyInterface      $policy
+     * @param Pool                 $pool
+     * @param CompositeRepository  $installedRepo
+     * @param Request              $request
+     * @param OperationInterface[] $operations
+     * @param OperationInterface   $operation
+     */
+    public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
+    {
+        parent::__construct($eventName);
+
+        $this->composer = $composer;
+        $this->io = $io;
+        $this->devMode = $devMode;
+        $this->policy = $policy;
+        $this->pool = $pool;
+        $this->installedRepo = $installedRepo;
+        $this->request = $request;
+        $this->operations = $operations;
+        $this->operation = $operation;
+    }
+
+    /**
+     * Returns the package instance.
+     *
+     * @return OperationInterface
+     */
+    public function getOperation()
+    {
+        return $this->operation;
+    }
+}

+ 75 - 0
src/Composer/Installer/PackageEvents.php

@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Installer;
+
+/**
+ * Package Events.
+ *
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class PackageEvents
+{
+    /**
+     * The PRE_PACKAGE_INSTALL event occurs before a package is installed.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const PRE_PACKAGE_INSTALL = 'pre-package-install';
+
+    /**
+     * The POST_PACKAGE_INSTALL event occurs after a package is installed.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const POST_PACKAGE_INSTALL = 'post-package-install';
+
+    /**
+     * The PRE_PACKAGE_UPDATE event occurs before a package is updated.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const PRE_PACKAGE_UPDATE = 'pre-package-update';
+
+    /**
+     * The POST_PACKAGE_UPDATE event occurs after a package is updated.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const POST_PACKAGE_UPDATE = 'post-package-update';
+
+    /**
+     * The PRE_PACKAGE_UNINSTALL event occurs before a package has been uninstalled.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall';
+
+    /**
+     * The POST_PACKAGE_UNINSTALL event occurs after a package has been uninstalled.
+     *
+     * The event listener method receives a Composer\Script\PackageEvent instance.
+     *
+     * @var string
+     */
+    const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
+}

+ 1 - 1
src/Composer/Script/CommandEvent.php

@@ -15,7 +15,7 @@ namespace Composer\Script;
 /**
  * The Command Event.
  *
- * @author François Pluchino <francois.pluchino@opendisplay.com>
+ * @deprecated use Composer\Script\Event instead
  */
 class CommandEvent extends Event
 {

+ 3 - 34
src/Composer/Script/PackageEvent.php

@@ -12,44 +12,13 @@
 
 namespace Composer\Script;
 
-use Composer\Composer;
-use Composer\IO\IOInterface;
-use Composer\DependencyResolver\Operation\OperationInterface;
+use Composer\Installer\PackageEvent as BasePackageEvent;
 
 /**
  * The Package Event.
  *
- * @author Jordi Boggiano <j.boggiano@seld.be>
+ * @deprecated Use Composer\Installer\PackageEvent instead
  */
-class PackageEvent extends Event
+class PackageEvent extends BasePackageEvent
 {
-    /**
-     * @var OperationInterface The package instance
-     */
-    private $operation;
-
-    /**
-     * Constructor.
-     *
-     * @param string             $name      The event name
-     * @param Composer           $composer  The composer object
-     * @param IOInterface        $io        The IOInterface object
-     * @param boolean            $devMode   Whether or not we are in dev mode
-     * @param OperationInterface $operation The operation object
-     */
-    public function __construct($name, Composer $composer, IOInterface $io, $devMode, OperationInterface $operation)
-    {
-        parent::__construct($name, $composer, $io, $devMode);
-        $this->operation = $operation;
-    }
-
-    /**
-     * Returns the package instance.
-     *
-     * @return OperationInterface
-     */
-    public function getOperation()
-    {
-        return $this->operation;
-    }
 }

+ 41 - 33
src/Composer/Script/ScriptEvents.php

@@ -74,112 +74,120 @@ class ScriptEvents
      */
     const POST_STATUS_CMD = 'post-status-cmd';
 
+    /** Deprecated constants below */
+
     /**
-     * The PRE_PACKAGE_INSTALL event occurs before a package is installed.
+     * The PRE_AUTOLOAD_DUMP event occurs before the autoload file is generated.
      *
-     * The event listener method receives a Composer\Script\PackageEvent instance.
+     * The event listener method receives a Composer\Script\Event instance.
      *
      * @var string
      */
-    const PRE_PACKAGE_INSTALL = 'pre-package-install';
+    const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump';
 
     /**
-     * The POST_PACKAGE_INSTALL event occurs after a package is installed.
+     * The POST_AUTOLOAD_DUMP event occurs after the autoload file has been generated.
      *
-     * The event listener method receives a Composer\Script\PackageEvent instance.
+     * The event listener method receives a Composer\Script\Event instance.
      *
      * @var string
      */
-    const POST_PACKAGE_INSTALL = 'post-package-install';
+    const POST_AUTOLOAD_DUMP = 'post-autoload-dump';
 
     /**
-     * The PRE_PACKAGE_UPDATE event occurs before a package is updated.
+     * The POST_ROOT_PACKAGE_INSTALL event occurs after the root package has been installed.
      *
      * The event listener method receives a Composer\Script\PackageEvent instance.
      *
      * @var string
      */
-    const PRE_PACKAGE_UPDATE = 'pre-package-update';
+    const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install';
 
     /**
-     * The POST_PACKAGE_UPDATE event occurs after a package is updated.
+     * The POST_CREATE_PROJECT event occurs after the create-project command has been executed.
+     * Note: Event occurs after POST_INSTALL_CMD
      *
      * The event listener method receives a Composer\Script\PackageEvent instance.
      *
      * @var string
      */
-    const POST_PACKAGE_UPDATE = 'post-package-update';
+    const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd';
 
     /**
-     * The PRE_PACKAGE_UNINSTALL event occurs before a package has been uninstalled.
+     * The PRE_ARCHIVE_CMD event occurs before the update command is executed.
      *
-     * The event listener method receives a Composer\Script\PackageEvent instance.
+     * The event listener method receives a Composer\Script\CommandEvent instance.
      *
      * @var string
      */
-    const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall';
+    const PRE_ARCHIVE_CMD = 'pre-archive-cmd';
 
     /**
-     * The POST_PACKAGE_UNINSTALL event occurs after a package has been uninstalled.
+     * The POST_ARCHIVE_CMD event occurs after the status command is executed.
      *
-     * The event listener method receives a Composer\Script\PackageEvent instance.
+     * The event listener method receives a Composer\Script\CommandEvent instance.
      *
      * @var string
      */
-    const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
+    const POST_ARCHIVE_CMD = 'post-archive-cmd';
 
     /**
-     * The PRE_AUTOLOAD_DUMP event occurs before the autoload file is generated.
+     * The PRE_PACKAGE_INSTALL event occurs before a package is installed.
      *
-     * The event listener method receives a Composer\Script\Event instance.
+     * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::PRE_PACKAGE_INSTALL instead.
      * @var string
      */
-    const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump';
+    const PRE_PACKAGE_INSTALL = 'pre-package-install';
 
     /**
-     * The POST_AUTOLOAD_DUMP event occurs after the autoload file has been generated.
+     * The POST_PACKAGE_INSTALL event occurs after a package is installed.
      *
-     * The event listener method receives a Composer\Script\Event instance.
+     * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::POST_PACKAGE_INSTALL instead.
      * @var string
      */
-    const POST_AUTOLOAD_DUMP = 'post-autoload-dump';
+    const POST_PACKAGE_INSTALL = 'post-package-install';
 
     /**
-     * The POST_ROOT_PACKAGE_INSTALL event occurs after the root package has been installed.
+     * The PRE_PACKAGE_UPDATE event occurs before a package is updated.
      *
      * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::PRE_PACKAGE_UPDATE instead.
      * @var string
      */
-    const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install';
+    const PRE_PACKAGE_UPDATE = 'pre-package-update';
 
     /**
-     * The POST_CREATE_PROJECT event occurs after the create-project command has been executed.
-     * Note: Event occurs after POST_INSTALL_CMD
+     * The POST_PACKAGE_UPDATE event occurs after a package is updated.
      *
      * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::POST_PACKAGE_UPDATE instead.
      * @var string
      */
-    const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd';
+    const POST_PACKAGE_UPDATE = 'post-package-update';
 
     /**
-     * The PRE_ARCHIVE_CMD event occurs before the update command is executed.
+     * The PRE_PACKAGE_UNINSTALL event occurs before a package has been uninstalled.
      *
-     * The event listener method receives a Composer\Script\CommandEvent instance.
+     * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::PRE_PACKAGE_UNINSTALL instead.
      * @var string
      */
-    const PRE_ARCHIVE_CMD = 'pre-archive-cmd';
+    const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall';
 
     /**
-     * The POST_ARCHIVE_CMD event occurs after the status command is executed.
+     * The POST_PACKAGE_UNINSTALL event occurs after a package has been uninstalled.
      *
-     * The event listener method receives a Composer\Script\CommandEvent instance.
+     * The event listener method receives a Composer\Script\PackageEvent instance.
      *
+     * @deprecated Use Composer\Installer\PackageEvents::POST_PACKAGE_UNINSTALL instead.
      * @var string
      */
-    const POST_ARCHIVE_CMD = 'post-archive-cmd';
+    const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
 }

+ 8 - 8
tests/Composer/Test/EventDispatcher/EventDispatcherTest.php

@@ -36,7 +36,7 @@ class EventDispatcherTest extends TestCase
             ->method('write')
             ->with('<error>Script Composer\Test\EventDispatcher\EventDispatcherTest::call handling the post-install-cmd event terminated with an exception</error>');
 
-        $dispatcher->dispatchCommandEvent(ScriptEvents::POST_INSTALL_CMD, false);
+        $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
     }
 
     public function testDispatcherCanConvertScriptEventToCommandEventForListener()
@@ -48,7 +48,7 @@ class EventDispatcherTest extends TestCase
 
         $this->assertEquals(1, $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false));
     }
-    
+
     public function testDispatcherDoesNotAttemptConversionForListenerWithoutTypehint()
     {
         $io = $this->getMock('Composer\IO\IOInterface');
@@ -85,7 +85,7 @@ class EventDispatcherTest extends TestCase
             ->with($command)
             ->will($this->returnValue(0));
 
-        $dispatcher->dispatchCommandEvent(ScriptEvents::POST_INSTALL_CMD, false);
+        $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
     }
 
     public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack()
@@ -121,7 +121,7 @@ class EventDispatcherTest extends TestCase
             ->with('Composer\Test\EventDispatcher\EventDispatcherTest', 'someMethod')
             ->will($this->returnValue(true));
 
-        $dispatcher->dispatchCommandEvent(ScriptEvents::POST_INSTALL_CMD, false);
+        $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
     }
 
     private function getDispatcherStubForListenersTest($listeners, $io)
@@ -167,7 +167,7 @@ class EventDispatcherTest extends TestCase
             ->will($this->returnValue($listener));
 
         ob_start();
-        $dispatcher->dispatchCommandEvent(ScriptEvents::POST_INSTALL_CMD, false);
+        $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
         $this->assertEquals('foo', trim(ob_get_clean()));
     }
 
@@ -193,7 +193,7 @@ class EventDispatcherTest extends TestCase
             ->with($this->equalTo('<error>Script '.$code.' handling the post-install-cmd event returned with an error</error>'));
 
         $this->setExpectedException('RuntimeException');
-        $dispatcher->dispatchCommandEvent(ScriptEvents::POST_INSTALL_CMD, false);
+        $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
     }
 
     public function testDispatcherInstallerEvents()
@@ -217,8 +217,8 @@ class EventDispatcherTest extends TestCase
         $installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
         $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
 
-        $dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request);
-        $dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, array());
+        $dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $policy, $pool, $installedRepo, $request);
+        $dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $policy, $pool, $installedRepo, $request, array());
     }
 
     public static function call()

+ 2 - 1
tests/Composer/Test/Installer/InstallerEventTest.php

@@ -25,11 +25,12 @@ class InstallerEventTest extends \PHPUnit_Framework_TestCase
         $installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
         $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
         $operations = array($this->getMock('Composer\DependencyResolver\Operation\OperationInterface'));
-        $event = new InstallerEvent('EVENT_NAME', $composer, $io, $policy, $pool, $installedRepo, $request, $operations);
+        $event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $policy, $pool, $installedRepo, $request, $operations);
 
         $this->assertSame('EVENT_NAME', $event->getName());
         $this->assertInstanceOf('Composer\Composer', $event->getComposer());
         $this->assertInstanceOf('Composer\IO\IOInterface', $event->getIO());
+        $this->assertTrue($event->isDevMode());
         $this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy());
         $this->assertInstanceOf('Composer\DependencyResolver\Pool', $event->getPool());
         $this->assertInstanceOf('Composer\Repository\CompositeRepository', $event->getInstalledRepo());