diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php
index 9bdd33ae3..465b7762e 100644
--- a/src/Composer/Command/CreateProjectCommand.php
+++ b/src/Composer/Command/CreateProjectCommand.php
@@ -183,6 +183,7 @@ EOT
}
$composer = Factory::create($io, null, $disablePlugins);
+ $composer->getEventDispatcher()->setRunScripts(!$noScripts);
// add the repository to the composer.json and use it for the install run later
if ($repositories !== null && $addRepository) {
@@ -208,10 +209,8 @@ EOT
$process = new ProcessExecutor($io);
$fs = new Filesystem($process);
- if ($noScripts === false) {
- // dispatch event
- $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
- }
+ // dispatch event
+ $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
// use the new config including the newly installed project
$config = $composer->getConfig();
@@ -225,7 +224,6 @@ EOT
$installer->setPreferSource($preferSource)
->setPreferDist($preferDist)
->setDevMode($installDevPackages)
- ->setRunScripts(!$noScripts)
->setIgnorePlatformRequirements($ignorePlatformReqs)
->setSuggestedPackagesReporter($this->suggestedPackagesReporter)
->setOptimizeAutoloader($config->get('optimize-autoloader'))
@@ -290,10 +288,8 @@ EOT
}
}
- if ($noScripts === false) {
- // dispatch event
- $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
- }
+ // dispatch event
+ $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
chdir($oldCwd);
$vendorComposerDir = $config->get('vendor-dir').'/composer';
diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php
index 17686a952..e6fe3d7e5 100644
--- a/src/Composer/Command/DumpAutoloadCommand.php
+++ b/src/Composer/Command/DumpAutoloadCommand.php
@@ -52,6 +52,7 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
+ $composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@@ -82,7 +83,6 @@ EOT
}
$generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix);
- $generator->setRunScripts(!$input->getOption('no-scripts'));
$generator->setIgnorePlatformRequirements($ignorePlatformReqs);
$numberOfClasses = $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php
index 55e1531c4..eda9c25cf 100644
--- a/src/Composer/Command/InstallCommand.php
+++ b/src/Composer/Command/InstallCommand.php
@@ -94,6 +94,7 @@ EOT
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
+ $composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ((!$composer->getLocker() || !$composer->getLocker()->isLocked()) && !HttpDownloader::isCurlEnabled()) {
$io->writeError('Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.');
@@ -123,7 +124,6 @@ EOT
->setPreferDist($preferDist)
->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader'))
- ->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix)
diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php
index f5f0c2282..3cd865126 100644
--- a/src/Composer/Command/RemoveCommand.php
+++ b/src/Composer/Command/RemoveCommand.php
@@ -202,6 +202,7 @@ EOT
// Update packages
$this->resetComposer();
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
+ $composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ($dryRun) {
$rootPackage = $composer->getPackage();
@@ -255,7 +256,6 @@ EOT
->setInstall(!$input->getOption('no-install'))
->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies)
->setIgnorePlatformRequirements($ignorePlatformReqs)
- ->setRunScripts(!$input->getOption('no-scripts'))
->setDryRun($dryRun)
;
diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php
index 5dd9cde18..c502cabf2 100644
--- a/src/Composer/Command/RequireCommand.php
+++ b/src/Composer/Command/RequireCommand.php
@@ -311,6 +311,7 @@ EOT
// Update packages
$this->resetComposer();
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
+ $composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ($input->getOption('dry-run')) {
$rootPackage = $composer->getPackage();
@@ -362,7 +363,6 @@ EOT
->setPreferSource($preferSource)
->setPreferDist($preferDist)
->setDevMode($updateDevMode)
- ->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix)
diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php
index 92d78be7b..86167c1b3 100644
--- a/src/Composer/Command/UpdateCommand.php
+++ b/src/Composer/Command/UpdateCommand.php
@@ -116,6 +116,7 @@ EOT
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
+ $composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if (!HttpDownloader::isCurlEnabled()) {
$io->writeError('Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.');
@@ -220,7 +221,6 @@ EOT
->setPreferDist($preferDist)
->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader'))
- ->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix)
diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php
index ea4493432..0ac0453af 100644
--- a/src/Composer/EventDispatcher/EventDispatcher.php
+++ b/src/Composer/EventDispatcher/EventDispatcher.php
@@ -53,6 +53,8 @@ class EventDispatcher
protected $process;
/** @var array>> */
protected $listeners = array();
+ /** @var bool */
+ protected $runScripts = true;
/** @var list */
private $eventStack;
@@ -71,6 +73,18 @@ class EventDispatcher
$this->eventStack = array();
}
+ /**
+ * Set whether to run scripts or not
+ *
+ * @param bool $runScripts
+ */
+ public function setRunScripts($runScripts = true)
+ {
+ $this->runScripts = (bool) $runScripts;
+
+ return $this;
+ }
+
/**
* Dispatch an event
*
@@ -421,7 +435,7 @@ class EventDispatcher
*/
protected function getListeners(Event $event)
{
- $scriptListeners = $this->getScriptListeners($event);
+ $scriptListeners = $this->runScripts ? $this->getScriptListeners($event) : array();
if (!isset($this->listeners[$event->getName()][0])) {
$this->listeners[$event->getName()][0] = array();