Browse Source

Fix env override regression, fixes #3820

Jordi Boggiano 10 years ago
parent
commit
b80038804f

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

@@ -316,7 +316,8 @@ EOT
         $io->writeError('<info>Created project in ' . $directory . '</info>');
         chdir($directory);
 
-        putenv('COMPOSER_ROOT_VERSION='.$package->getPrettyVersion());
+        $_SERVER['COMPOSER_ROOT_VERSION'] = $package->getPrettyVersion();
+        putenv('COMPOSER_ROOT_VERSION='.$_SERVER['COMPOSER_ROOT_VERSION']);
 
         return $installedFromVcs;
     }

+ 2 - 1
src/Composer/Command/RunScriptCommand.php

@@ -87,7 +87,8 @@ EOT
         // 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)) {
-            putenv('PATH='.realpath($binDir).PATH_SEPARATOR.getenv('PATH'));
+            $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
+            putenv('PATH='.$_SERVER['PATH']);
         }
 
         $args = $input->getArgument('args');

+ 2 - 1
src/Composer/Command/ScriptAliasCommand.php

@@ -57,7 +57,8 @@ EOT
         // 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)) {
-            putenv('PATH='.realpath($binDir).PATH_SEPARATOR.getenv('PATH'));
+            $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
+            putenv('PATH='.$_SERVER['PATH']);
         }
 
         $args = $input->getArguments();

+ 4 - 0
src/Composer/Util/Git.php

@@ -164,18 +164,22 @@ class Git
         // added in git 1.7.1, prevents prompting the user for username/password
         if (getenv('GIT_ASKPASS') !== 'echo') {
             putenv('GIT_ASKPASS=echo');
+            unset($_SERVER['GIT_ASKPASS']);
         }
 
         // clean up rogue git env vars in case this is running in a git hook
         if (getenv('GIT_DIR')) {
             putenv('GIT_DIR');
+            unset($_SERVER['GIT_DIR']);
         }
         if (getenv('GIT_WORK_TREE')) {
             putenv('GIT_WORK_TREE');
+            unset($_SERVER['GIT_WORK_TREE']);
         }
 
         // clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
         putenv("DYLD_LIBRARY_PATH");
+        unset($_SERVER['DYLD_LIBRARY_PATH']);
     }
 
     public static function getGitHubDomainsRegex(Config $config)

+ 1 - 1
src/Composer/Util/ProcessExecutor.php

@@ -56,7 +56,7 @@ class ProcessExecutor
 
         $this->captureOutput = count(func_get_args()) > 1;
         $this->errorOutput = null;
-        $process = new Process($command, $cwd, array('LANGUAGE' => 'C') + $_ENV + $_SERVER, null, static::getTimeout());
+        $process = new Process($command, $cwd, array_replace($_ENV, $_SERVER, array('LANGUAGE' => 'C')), null, static::getTimeout());
 
         $callback = is_callable($output) ? $output : array($this, 'outputHandler');
         $process->run($callback);

+ 1 - 0
src/Composer/Util/Svn.php

@@ -81,6 +81,7 @@ class Svn
     {
         // clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
         putenv("DYLD_LIBRARY_PATH");
+        unset($_SERVER['DYLD_LIBRARY_PATH']);
     }
 
     /**

+ 4 - 2
tests/Composer/Test/AllFunctionalTest.php

@@ -42,7 +42,8 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
         }
         if ($this->oldenv) {
             $fs->removeDirectory(getenv('COMPOSER_HOME'));
-            putenv('COMPOSER_HOME='.$this->oldenv);
+            $_SERVER['COMPOSER_HOME'] = $this->oldenv;
+            putenv('COMPOSER_HOME='.$_SERVER['COMPOSER_HOME']);
             $this->oldenv = null;
         }
     }
@@ -86,7 +87,8 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
         $testData = $this->parseTestFile($testFile);
 
         $this->oldenv = getenv('COMPOSER_HOME');
-        putenv('COMPOSER_HOME='.$this->testDir.'home');
+        $_SERVER['COMPOSER_HOME'] = $this->testDir.'home';
+        putenv('COMPOSER_HOME='.$_SERVER['COMPOSER_HOME']);
 
         $cmd = 'php '.escapeshellarg(self::$pharPath).' --no-ansi '.$testData['RUN'];
         $proc = new Process($cmd, __DIR__.'/Fixtures/functional', null, null, 300);