Skip to content

[Process] Deprecate Process::inheritEnvironmentVariables() #32475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ MonologBridge
--------------

* The `RouteProcessor` has been marked final.

Process
-------

* Deprecated the `Process::inheritEnvironmentVariables()` method: env variables are always inherited.

PropertyAccess
--------------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ MonologBridge
Process
-------

* Removed the `Process::inheritEnvironmentVariables()` method: env variables are always inherited.
* Removed the `Process::setCommandline()` and the `PhpProcess::setPhpBinary()` methods.
* Commands must be defined as arrays when creating a `Process` instance.

Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Bundle/WebServerBundle/WebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ private function createServerProcess(WebServerConfig $config)

if (\in_array('APP_ENV', explode(',', getenv('SYMFONY_DOTENV_VARS')))) {
$process->setEnv(['APP_ENV' => false]);
$process->inheritEnvironmentVariables();

if (!method_exists(Process::class, 'fromShellCommandline')) {
// Symfony 3.4 does not inherit env vars by default:
$process->inheritEnvironmentVariables();
}
}

return $process;
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/Dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,12 @@ private function resolveCommands($value)
}

$process = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline('echo '.$matches[0]) : new Process('echo '.$matches[0]);
$process->inheritEnvironmentVariables(true);

if (!method_exists(Process::class, 'fromShellCommandline')) {
// Symfony 3.4 does not inherit env vars by default:
$process->inheritEnvironmentVariables();
}

$process->setEnv($this->values);
try {
$process->mustRun();
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Process/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.4.0
-----

* deprecated `Process::inheritEnvironmentVariables()`: env variables are always inherited.

4.2.0
-----

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,13 @@ public function setInput($input)
* @param bool $inheritEnv
*
* @return self The current Process instance
*
* @deprecated since Symfony 4.4, env variables are always inherited
*/
public function inheritEnvironmentVariables($inheritEnv = true)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, env variables are always inherited.', __METHOD__), E_USER_DEPRECATED);

if (!$inheritEnv) {
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
}
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,6 @@ public function testSetBadEnv()
{
$process = $this->getProcess('echo hello');
$process->setEnv(['bad%%' => '123']);
$process->inheritEnvironmentVariables(true);

$process->run();

Expand All @@ -1419,7 +1418,6 @@ public function testEnvBackupDoesNotDeleteExistingVars()
$_ENV['existing_var'] = 'foo';
$process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"');
$process->setEnv(['existing_var' => 'bar', 'new_test_var' => 'foo']);
$process->inheritEnvironmentVariables();

$process->run();

Expand Down Expand Up @@ -1581,7 +1579,6 @@ private function getProcess($commandline, string $cwd = null, array $env = null,
} else {
$process = new Process($commandline, $cwd, $env, $input, $timeout);
}
$process->inheritEnvironmentVariables();

if (self::$process) {
self::$process->stop(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private function getServerProcess(): Process
'COMPONENT_ROOT' => __DIR__.'/../../',
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
]);
$process->inheritEnvironmentVariables(true);

return $process->setTimeout(9);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private function getServerProcess(): Process
'COMPONENT_ROOT' => __DIR__.'/../../',
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
]);
$process->inheritEnvironmentVariables(true);

return $process->setTimeout(9);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require-dev": {
"ext-iconv": "*",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/process": "^3.4|^4.0|^5.0",
"symfony/process": "^4.4|^5.0",
"twig/twig": "~1.34|~2.4"
},
"conflict": {
Expand Down