From 2609cfdd1dada00cb916559ff7a97a5c8c1fc584 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 10 Feb 2016 14:10:52 +0000 Subject: [PATCH] Always set bin-dir into PATH before calling scripts, fixes #4852, closes #4898 --- src/Composer/Command/RunScriptCommand.php | 7 ------- src/Composer/Command/ScriptAliasCommand.php | 7 ------- src/Composer/EventDispatcher/EventDispatcher.php | 10 ++++++++++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index 5ad87bf40..e1cf17892 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -84,13 +84,6 @@ EOT throw new \InvalidArgumentException(sprintf('Script "%s" is not defined in this package', $script)); } - // add the bin dir to the PATH to make local binaries of deps usable in scripts - $binDir = $composer->getConfig()->get('bin-dir'); - if (is_dir($binDir)) { - $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH'); - putenv('PATH='.$_SERVER['PATH']); - } - $args = $input->getArgument('args'); return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args); diff --git a/src/Composer/Command/ScriptAliasCommand.php b/src/Composer/Command/ScriptAliasCommand.php index b8f0abff5..aeb83b0a4 100644 --- a/src/Composer/Command/ScriptAliasCommand.php +++ b/src/Composer/Command/ScriptAliasCommand.php @@ -54,13 +54,6 @@ EOT { $composer = $this->getComposer(); - // add the bin dir to the PATH to make local binaries of deps usable in scripts - $binDir = $composer->getConfig()->get('bin-dir'); - if (is_dir($binDir)) { - $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH'); - putenv('PATH='.$_SERVER['PATH']); - } - $args = $input->getArguments(); return $composer->getEventDispatcher()->dispatchScript($this->script, $input->getOption('dev') || !$input->getOption('no-dev'), $args['args']); diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index b9a879a01..9b73cf00c 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -145,6 +145,16 @@ class EventDispatcher */ protected function doDispatch(Event $event) { + // add the bin dir to the PATH to make local binaries of deps usable in scripts + $binDir = $this->composer->getConfig()->get('bin-dir'); + if (is_dir($binDir)) { + $binDir = realpath($binDir); + if (isset($_SERVER['PATH']) && !preg_match('{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}', $_SERVER['PATH'])) { + $_SERVER['PATH'] = $binDir.PATH_SEPARATOR.getenv('PATH'); + putenv('PATH='.$_SERVER['PATH']); + } + } + $listeners = $this->getListeners($event); $this->pushEvent($event);