1
0
Fork 0

Separated the scripts events in 2 arrays because they need to be called by different dispatchers.

pull/2800/merge
Sandy Pleyte 2014-02-19 13:38:51 +01:00 committed by Jordi Boggiano
parent 2618e9a4f1
commit b9efdd8348
1 changed files with 30 additions and 15 deletions

View File

@ -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);
}
}
}