Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f4ee74

Browse files
author
Robin Chalas
committed
[Console] Define APP_ENV/APP_DEBUG from argv via Application::bootstrapEnv()
1 parent664a032 commit6f4ee74

File tree

6 files changed

+98
-11
lines changed

6 files changed

+98
-11
lines changed

‎UPGRADE-4.2.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ FrameworkBundle
175175
```
176176
* The `ContainerAwareCommand` class has been deprecated, use `Symfony\Component\Console\Command\Command`
177177
with dependency injection instead.
178-
* The `--env` console option and its "-e" shortcuthave been deprecated,
179-
set the "APP_ENV" environment variable instead.
180-
* The `--no-debug` console option has been deprecated,
181-
set the "APP_DEBUG" environment variable to "0" instead.
178+
* The `--env` console option and its "-e" shortcuthavee been deprecated, set the "APP_ENV" environment variable
179+
or use `Symfony\Component\Console\Application::bootstrapEnv()` instead.
180+
* The `--no-debug` console option has been deprecated, set the "APP_DEBUG" environment variable to "0"
181+
or use `Symfony\Component\Console\Application::bootstrapEnv()` instead.
182182
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter.
183183
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
184184
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated.

‎UPGRADE-5.0.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ FrameworkBundle
165165
* The `ContainerAwareCommand` class has been removed, use `Symfony\Component\Console\Command\Command`
166166
with dependency injection instead.
167167
* The `--env` console option and its "-e" shortcut have been removed,
168-
set the "APP_ENV" environment variable instead.
169-
* The `--no-debug` console option has been removed,
170-
set the "APP_DEBUG" environment variable to "0" instead.
168+
set the "APP_ENV" environment variable instead or use `Symfony\Component\Console\Application::bootstrapEnv()` instead.
169+
* The `--no-debug` console option has been removed,set the "APP_DEBUG" environment variable to "0"
170+
or use `Symfony\Component\Console\Application::bootstrapEnv()` instead.
171171
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been removed, use the `trans()` one instead with a `%count%` parameter.
172172
* Removed support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
173173
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been removed.

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ CHANGELOG
1515
* Removed the`framework.messenger.encoder` and`framework.messenger.decoder` options. Use the`framework.messenger.serializer.id` option to replace the Messenger serializer.
1616
* Deprecated the`ContainerAwareCommand` class in favor of`Symfony\Component\Console\Command\Command`
1717
* Made`debug:container` and`debug:autowiring` ignore backslashes in service ids
18-
* Deprecated the`--env` console option and its "-e" shortcut, set
19-
the "APP_ENV" environment variable instead.
20-
* Deprecated the`--no-debug` console option, set the "APP_DEBUG"
21-
environment variable to "0" instead.
18+
* Deprecated the`--env` console option and its "-e" shortcut, set the "APP_ENV" environment variable
19+
or use`Symfony\Component\Console\Application::bootstrapEnv()` instead.
20+
* Deprecated the`--no-debug` console option, set the "APP_DEBUG"environment variable to "0"
21+
or use`Symfony\Component\Console\Application::bootstrapEnv()` instead.
2222
* Deprecated the`Templating\Helper\TranslatorHelper::transChoice()` method, use the`trans()` one instead with a`%count%` parameter
2323
* Deprecated`CacheCollectorPass`. Use`Symfony\Component\Cache\DependencyInjection\CacheCollectorPass` instead.
2424
* Deprecated`CachePoolClearerPass`. Use`Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass` instead.

‎src/Symfony/Component/Console/Application.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,35 @@ public function setDefaultCommand($commandName, $isSingleCommand = false)
10911091
return$this;
10921092
}
10931093

1094+
/**
1095+
* Defines the "APP_ENV" and "APP_DEBUG" environment variables from --env and --no-debug argv options.
1096+
*/
1097+
publicstaticfunctionbootstrapEnv(array &$argv)
1098+
{
1099+
for ($i =0;$i <\count($argv) &&'--' !==$v =$argv[$i]; ++$i) {
1100+
if ('--no-debug' ===$v) {
1101+
putenv('APP_DEBUG='.(int)$_SERVER['APP_DEBUG'] =$_ENV['APP_DEBUG'] =false);
1102+
$argvUnset[$i] =true;
1103+
break;
1104+
}
1105+
}
1106+
1107+
for ($i =0;$i <\count($argv) &&'--' !==$v =$argv[$i]; ++$i) {
1108+
if (!$v ||'-' !==$v[0] || !preg_match('/^-(?:-env(?:=|$)|e=?)(.*)$/D',$v,$v)) {
1109+
continue;
1110+
}
1111+
if (!empty($v[1]) || !empty($argv[1 +$i])) {
1112+
putenv('APP_ENV='.$_SERVER['APP_ENV'] =$_ENV['APP_ENV'] =empty($v[1]) ?$argv[1 +$i] :$v[1]);
1113+
$argvUnset[$i] =$argvUnset[$i +empty($v[1])] =true;
1114+
}
1115+
break;
1116+
}
1117+
1118+
if (!empty($argvUnset)) {
1119+
$argv =array_values(array_diff_key($argv,$argvUnset));
1120+
}
1121+
}
1122+
10941123
privatefunctionsplitStringByWidth($string,$width)
10951124
{
10961125
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.

‎src/Symfony/Component/Console/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* made the`ProcessHelper` class final
1212
* added`WrappableOutputFormatterInterface::formatAndWrap()` (implemented in`OutputFormatter`)
1313
* added`capture_stderr_separately` option to`CommandTester::execute()`
14+
* added`Application::bootstrapEnv()`
1415

1516
4.1.0
1617
-----

‎src/Symfony/Component/Console/Tests/ApplicationTest.php‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,63 @@ public function testThrowingErrorListener()
17031703
$tester->run(array('command' =>'foo'));
17041704
}
17051705

1706+
publicfunctiontestBootstrapEnv()
1707+
{
1708+
$argv =array('--no-debug','--env=testBootstrapEnv','foo=bar');
1709+
Application::bootstrapEnv($argv);
1710+
1711+
$this->assertFalse($_SERVER['APP_DEBUG']);
1712+
$this->assertFalse($_ENV['APP_DEBUG']);
1713+
$this->assertSame('0',getenv('APP_DEBUG'));
1714+
$this->assertSame('testBootstrapEnv',$_SERVER['APP_ENV']);
1715+
$this->assertSame('testBootstrapEnv',$_ENV['APP_ENV']);
1716+
$this->assertSame('testBootstrapEnv',getenv('APP_ENV'));
1717+
$this->assertSame(array('foo=bar'),$argv);
1718+
1719+
unset($_SERVER['APP_ENV']);
1720+
unset($_ENV['APP_ENV']);
1721+
putenv('APP_ENV');
1722+
unset($_SERVER['APP_DEBUG']);
1723+
unset($_ENV['APP_DEBUG']);
1724+
putenv('APP_DEBUG');
1725+
1726+
$argv =array('--env','testBootstrapEnv','foo=bar');
1727+
Application::bootstrapEnv($argv);
1728+
1729+
$this->assertSame('testBootstrapEnv',$_SERVER['APP_ENV']);
1730+
$this->assertSame('testBootstrapEnv',$_ENV['APP_ENV']);
1731+
$this->assertSame('testBootstrapEnv',getenv('APP_ENV'));
1732+
$this->assertSame(array('foo=bar'),$argv);
1733+
1734+
unset($_SERVER['APP_ENV']);
1735+
unset($_ENV['APP_ENV']);
1736+
putenv('APP_ENV');
1737+
1738+
$argv =array('-e','testBootstrapEnv','foo=bar');
1739+
Application::bootstrapEnv($argv);
1740+
1741+
$this->assertSame('testBootstrapEnv',$_SERVER['APP_ENV']);
1742+
$this->assertSame('testBootstrapEnv',$_ENV['APP_ENV']);
1743+
$this->assertSame('testBootstrapEnv',getenv('APP_ENV'));
1744+
$this->assertSame(array('foo=bar'),$argv);
1745+
1746+
unset($_SERVER['APP_ENV']);
1747+
unset($_ENV['APP_ENV']);
1748+
putenv('APP_ENV');
1749+
1750+
$argv =array('-e=testBootstrapEnv','foo=bar');
1751+
Application::bootstrapEnv($argv);
1752+
1753+
$this->assertSame('testBootstrapEnv',$_SERVER['APP_ENV']);
1754+
$this->assertSame('testBootstrapEnv',$_ENV['APP_ENV']);
1755+
$this->assertSame('testBootstrapEnv',getenv('APP_ENV'));
1756+
$this->assertSame(array('foo=bar'),$argv);
1757+
1758+
unset($_SERVER['APP_ENV']);
1759+
unset($_ENV['APP_ENV']);
1760+
putenv('APP_ENV');
1761+
}
1762+
17061763
protectedfunctiontearDown()
17071764
{
17081765
putenv('SHELL_VERBOSITY');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp