feature #32475 [Process] Deprecate Process::inheritEnvironmentVariables() (ogizanagi)
This PR was merged into the 4.4 branch.
Discussion
----------
[Process] Deprecate Process::inheritEnvironmentVariables()
| Q | A
| ------------- | ---
| Branch? | 4.4 <!-- see below -->
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | N/A
IIUC, this method was kept as a BC layer from 3.4 to 4.0 to switch to the "inherit env vars" behavior, inciting developers to opt-in in 3.4. Since 4.0, env vars are always inherited, and this method doesn't allow to opt-out. So, time to remove it?
---
refs:
- https://github.com/symfony/symfony/pull/21470
- https://github.com/symfony/symfony/pull/22836
Commits
-------
af9bad31c6
[Process] Deprecate Process::inheritEnvironmentVariables()
This commit is contained in:
commit
b07933d99e
@ -119,6 +119,11 @@ MonologBridge
|
|||||||
|
|
||||||
* The `RouteProcessor` has been marked final.
|
* The `RouteProcessor` has been marked final.
|
||||||
|
|
||||||
|
Process
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Deprecated the `Process::inheritEnvironmentVariables()` method: env variables are always inherited.
|
||||||
|
|
||||||
PropertyAccess
|
PropertyAccess
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
@ -334,6 +334,7 @@ MonologBridge
|
|||||||
Process
|
Process
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
* Removed the `Process::inheritEnvironmentVariables()` method: env variables are always inherited.
|
||||||
* Removed the `Process::setCommandline()` and the `PhpProcess::setPhpBinary()` methods.
|
* Removed the `Process::setCommandline()` and the `PhpProcess::setPhpBinary()` methods.
|
||||||
* Commands must be defined as arrays when creating a `Process` instance.
|
* Commands must be defined as arrays when creating a `Process` instance.
|
||||||
|
|
||||||
|
@ -167,8 +167,12 @@ class WebServer
|
|||||||
|
|
||||||
if (\in_array('APP_ENV', explode(',', getenv('SYMFONY_DOTENV_VARS')))) {
|
if (\in_array('APP_ENV', explode(',', getenv('SYMFONY_DOTENV_VARS')))) {
|
||||||
$process->setEnv(['APP_ENV' => false]);
|
$process->setEnv(['APP_ENV' => false]);
|
||||||
|
|
||||||
|
if (!method_exists(Process::class, 'fromShellCommandline')) {
|
||||||
|
// Symfony 3.4 does not inherit env vars by default:
|
||||||
$process->inheritEnvironmentVariables();
|
$process->inheritEnvironmentVariables();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,12 @@ final class Dotenv
|
|||||||
}
|
}
|
||||||
|
|
||||||
$process = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline('echo '.$matches[0]) : new Process('echo '.$matches[0]);
|
$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);
|
$process->setEnv($this->values);
|
||||||
try {
|
try {
|
||||||
$process->mustRun();
|
$process->mustRun();
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
4.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* deprecated `Process::inheritEnvironmentVariables()`: env variables are always inherited.
|
||||||
|
|
||||||
4.2.0
|
4.2.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -1210,9 +1210,13 @@ class Process implements \IteratorAggregate
|
|||||||
* @param bool $inheritEnv
|
* @param bool $inheritEnv
|
||||||
*
|
*
|
||||||
* @return self The current Process instance
|
* @return self The current Process instance
|
||||||
|
*
|
||||||
|
* @deprecated since Symfony 4.4, env variables are always inherited
|
||||||
*/
|
*/
|
||||||
public function inheritEnvironmentVariables($inheritEnv = true)
|
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) {
|
if (!$inheritEnv) {
|
||||||
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
|
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
|
||||||
}
|
}
|
||||||
|
@ -1405,7 +1405,6 @@ class ProcessTest extends TestCase
|
|||||||
{
|
{
|
||||||
$process = $this->getProcess('echo hello');
|
$process = $this->getProcess('echo hello');
|
||||||
$process->setEnv(['bad%%' => '123']);
|
$process->setEnv(['bad%%' => '123']);
|
||||||
$process->inheritEnvironmentVariables(true);
|
|
||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
@ -1419,7 +1418,6 @@ class ProcessTest extends TestCase
|
|||||||
$_ENV['existing_var'] = 'foo';
|
$_ENV['existing_var'] = 'foo';
|
||||||
$process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"');
|
$process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"');
|
||||||
$process->setEnv(['existing_var' => 'bar', 'new_test_var' => 'foo']);
|
$process->setEnv(['existing_var' => 'bar', 'new_test_var' => 'foo']);
|
||||||
$process->inheritEnvironmentVariables();
|
|
||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
@ -1581,7 +1579,6 @@ EOTXT;
|
|||||||
} else {
|
} else {
|
||||||
$process = new Process($commandline, $cwd, $env, $input, $timeout);
|
$process = new Process($commandline, $cwd, $env, $input, $timeout);
|
||||||
}
|
}
|
||||||
$process->inheritEnvironmentVariables();
|
|
||||||
|
|
||||||
if (self::$process) {
|
if (self::$process) {
|
||||||
self::$process->stop(0);
|
self::$process->stop(0);
|
||||||
|
@ -88,7 +88,6 @@ DUMP
|
|||||||
'COMPONENT_ROOT' => __DIR__.'/../../',
|
'COMPONENT_ROOT' => __DIR__.'/../../',
|
||||||
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
|
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
|
||||||
]);
|
]);
|
||||||
$process->inheritEnvironmentVariables(true);
|
|
||||||
|
|
||||||
return $process->setTimeout(9);
|
return $process->setTimeout(9);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,6 @@ DUMP
|
|||||||
'COMPONENT_ROOT' => __DIR__.'/../../',
|
'COMPONENT_ROOT' => __DIR__.'/../../',
|
||||||
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
|
'VAR_DUMPER_SERVER' => self::VAR_DUMPER_SERVER,
|
||||||
]);
|
]);
|
||||||
$process->inheritEnvironmentVariables(true);
|
|
||||||
|
|
||||||
return $process->setTimeout(9);
|
return $process->setTimeout(9);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-iconv": "*",
|
"ext-iconv": "*",
|
||||||
"symfony/console": "^3.4|^4.0|^5.0",
|
"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"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
|
Reference in New Issue
Block a user