Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3c5fda

Browse files
Revert "bug #29154 [FrameworkBundle] Define APP_ENV/APP_DEBUG from argv via Application::bootstrapEnv() (chalasr)"
This reverts commit 9253199, reversing changes made to 664a032.
1 parent 6eb5f93 commit f3c5fda

File tree

5 files changed

+6
-132
lines changed

5 files changed

+6
-132
lines changed

UPGRADE-4.2.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,8 @@ FrameworkBundle
177177
with dependency injection instead.
178178
* The `--env` and `--no-debug` console options have been deprecated, define the `APP_ENV` and
179179
`APP_DEBUG` environment variables instead.
180-
If you want to keep using `--env` and `--no-debug`, update your `bin/console` file to make it call
181-
`Application::bootstrapEnv()`.
182-
183-
Before:
184-
```php
185-
$input = new ArgvInput();
186-
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
187-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
188-
$kernel = new Kernel($env, $debug);
189-
$application = new Application($kernel);
190-
$application->run($input);
191-
```
192-
193-
After:
194-
```php
195-
Application::bootstrapEnv($_SERVER['argv']);
196-
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
197-
$application = new Application($kernel);
198-
$application->run();
199-
```
200-
180+
If you want to keep using `--env` and `--no-debug`, you can take inspiration from
181+
https://github.com/symfony/recipes/blob/master/symfony/console/3.3/bin/console
201182
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter.
202183
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
203184
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated.

UPGRADE-5.0.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,8 @@ FrameworkBundle
166166
with dependency injection instead.
167167
* The `--env` and `--no-debug` console options have been removed, define the `APP_ENV` and
168168
`APP_DEBUG` environment variables instead.
169-
If you want to keep using `--env` and `--no-debug`, update your `bin/console` file to make it call
170-
`Application::bootstrapEnv()`.
171-
172-
Before:
173-
```php
174-
$input = new ArgvInput();
175-
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
176-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
177-
$kernel = new Kernel($env, $debug);
178-
$application = new Application($kernel);
179-
$application->run($input);
180-
```
181-
182-
After:
183-
```php
184-
Application::bootstrapEnv($_SERVER['argv']);
185-
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
186-
$application = new Application($kernel);
187-
$application->run();
188-
```
189-
169+
If you want to keep using `--env` and `--no-debug`, you can take inspiration from
170+
https://github.com/symfony/recipes/blob/master/symfony/console/3.3/bin/console
190171
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been removed, use the `trans()` one instead with a `%count%` parameter.
191172
* Removed support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
192173
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been removed.

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ 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 the "APP_ENV" environment variable
19-
or use `Application::bootstrapEnv()` instead.
20-
* Deprecated the `--no-debug` console option, set the "APP_DEBUG" environment variable to "0"
21-
or use `Application::bootstrapEnv()` instead.
18+
* Deprecated `--env` and `--no-debug` console options, define the `APP_ENV` and `APP_DEBUG` environment variables or
19+
parse input arguments as done in https://github.com/symfony/recipes/blob/master/symfony/console/3.3/bin/console instead
2220
* Deprecated the `Templating\Helper\TranslatorHelper::transChoice()` method, use the `trans()` one instead with a `%count%` parameter
2321
* Deprecated `CacheCollectorPass`. Use `Symfony\Component\Cache\DependencyInjection\CacheCollectorPass` instead.
2422
* Deprecated `CachePoolClearerPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass` instead.

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -207,35 +207,6 @@ protected function registerCommands()
207207
}
208208
}
209209

210-
/**
211-
* Defines the "APP_ENV" and "APP_DEBUG" environment variables by consuming --env and --no-debug from the command line arguments.
212-
*/
213-
public static function bootstrapEnv(array &$argv)
214-
{
215-
for ($i = 0; $i < \count($argv) && '--' !== $v = $argv[$i]; ++$i) {
216-
if ('--no-debug' === $v) {
217-
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
218-
$argvUnset[$i] = true;
219-
break;
220-
}
221-
}
222-
223-
for ($i = 0; $i < \count($argv) && '--' !== $v = $argv[$i]; ++$i) {
224-
if (!$v || '-' !== $v[0] || !preg_match('/^-(?:-env(?:=|$)|e=?)(.*)$/D', $v, $v)) {
225-
continue;
226-
}
227-
if (!empty($v[1]) || !empty($argv[1 + $i])) {
228-
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = empty($v[1]) ? $argv[1 + $i] : $v[1]);
229-
$argvUnset[$i] = $argvUnset[$i + empty($v[1])] = true;
230-
}
231-
break;
232-
}
233-
234-
if (!empty($argvUnset)) {
235-
$argv = array_values(array_diff_key($argv, $argvUnset));
236-
}
237-
}
238-
239210
private function renderRegistrationErrors(InputInterface $input, OutputInterface $output)
240211
{
241212
if ($output instanceof ConsoleOutputInterface) {

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -283,63 +283,6 @@ private function createBundleMock(array $commands)
283283

284284
return $bundle;
285285
}
286-
287-
public function testBootstrapEnv()
288-
{
289-
$argv = array('--no-debug', '--env=testBootstrapEnv', 'foo=bar');
290-
Application::bootstrapEnv($argv);
291-
292-
$this->assertSame($_SERVER['APP_DEBUG'], '0');
293-
$this->assertSame($_ENV['APP_DEBUG'], '0');
294-
$this->assertSame('0', getenv('APP_DEBUG'));
295-
$this->assertSame('testBootstrapEnv', $_SERVER['APP_ENV']);
296-
$this->assertSame('testBootstrapEnv', $_ENV['APP_ENV']);
297-
$this->assertSame('testBootstrapEnv', getenv('APP_ENV'));
298-
$this->assertSame(array('foo=bar'), $argv);
299-
300-
unset($_SERVER['APP_ENV']);
301-
unset($_ENV['APP_ENV']);
302-
putenv('APP_ENV');
303-
unset($_SERVER['APP_DEBUG']);
304-
unset($_ENV['APP_DEBUG']);
305-
putenv('APP_DEBUG');
306-
307-
$argv = array('--env', 'testBootstrapEnv', 'foo=bar');
308-
Application::bootstrapEnv($argv);
309-
310-
$this->assertSame('testBootstrapEnv', $_SERVER['APP_ENV']);
311-
$this->assertSame('testBootstrapEnv', $_ENV['APP_ENV']);
312-
$this->assertSame('testBootstrapEnv', getenv('APP_ENV'));
313-
$this->assertSame(array('foo=bar'), $argv);
314-
315-
unset($_SERVER['APP_ENV']);
316-
unset($_ENV['APP_ENV']);
317-
putenv('APP_ENV');
318-
319-
$argv = array('-e', 'testBootstrapEnv', 'foo=bar');
320-
Application::bootstrapEnv($argv);
321-
322-
$this->assertSame('testBootstrapEnv', $_SERVER['APP_ENV']);
323-
$this->assertSame('testBootstrapEnv', $_ENV['APP_ENV']);
324-
$this->assertSame('testBootstrapEnv', getenv('APP_ENV'));
325-
$this->assertSame(array('foo=bar'), $argv);
326-
327-
unset($_SERVER['APP_ENV']);
328-
unset($_ENV['APP_ENV']);
329-
putenv('APP_ENV');
330-
331-
$argv = array('-e=testBootstrapEnv', 'foo=bar');
332-
Application::bootstrapEnv($argv);
333-
334-
$this->assertSame('testBootstrapEnv', $_SERVER['APP_ENV']);
335-
$this->assertSame('testBootstrapEnv', $_ENV['APP_ENV']);
336-
$this->assertSame('testBootstrapEnv', getenv('APP_ENV'));
337-
$this->assertSame(array('foo=bar'), $argv);
338-
339-
unset($_SERVER['APP_ENV']);
340-
unset($_ENV['APP_ENV']);
341-
putenv('APP_ENV');
342-
}
343286
}
344287

345288
class ThrowingCommand extends Command

0 commit comments

Comments
 (0)