From b9efdd8348be7518b9b7404774936c402f030c3a Mon Sep 17 00:00:00 2001 From: Sandy Pleyte Date: Wed, 19 Feb 2014 13:38:51 +0100 Subject: [PATCH] Separated the scripts events in 2 arrays because they need to be called by different dispatchers. --- src/Composer/Command/RunScriptCommand.php | 45 +++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index 81b599858..0ccf868ad 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -23,6 +23,30 @@ use Symfony\Component\Console\Output\OutputInterface; */ class RunScriptCommand extends Command { + /** + * @var array Array with command events + */ + protected $commandEvents = array( + ScriptEvents::PRE_INSTALL_CMD, + ScriptEvents::POST_INSTALL_CMD, + ScriptEvents::PRE_UPDATE_CMD, + ScriptEvents::POST_UPDATE_CMD, + 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::PRE_ARCHIVE_CMD, + ScriptEvents::POST_ARCHIVE_CMD, + ScriptEvents::PRE_AUTOLOAD_DUMP, + ScriptEvents::POST_AUTOLOAD_DUMP + ); + protected function configure() { $this @@ -45,20 +69,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { $script = $input->getArgument('script'); - if (!in_array($script, array( - ScriptEvents::PRE_INSTALL_CMD, - ScriptEvents::POST_INSTALL_CMD, - ScriptEvents::PRE_UPDATE_CMD, - ScriptEvents::POST_UPDATE_CMD, - ScriptEvents::PRE_STATUS_CMD, - ScriptEvents::POST_STATUS_CMD, - ScriptEvents::POST_ROOT_PACKAGE_INSTALL, - ScriptEvents::POST_CREATE_PROJECT_CMD, - ScriptEvents::PRE_ARCHIVE_CMD, - ScriptEvents::POST_ARCHIVE_CMD, - ScriptEvents::PRE_AUTOLOAD_DUMP, - ScriptEvents::POST_AUTOLOAD_DUMP - ))) { + if (!in_array($script, $this->commandEvents) || !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)); } @@ -66,6 +77,10 @@ EOT throw new \InvalidArgumentException(sprintf('Script "%s" does not exist', $script)); } - $this->getComposer()->getEventDispatcher()->dispatchCommandEvent($script, $input->getOption('dev') || !$input->getOption('no-dev')); + if (in_array($script, $this->commandEvents)) { + $this->getComposer()->getEventDispatcher()->dispatchCommandEvent($script, $input->getOption('dev') || !$input->getOption('no-dev')); + } else { + $this->getComposer()->getEventDispatcher()->dispatchScript($script); + } } }