8000 Improve env handling · symfony/recipes@bafbfd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit bafbfd0

Browse files
committed
Improve env handling
1 parent a54f28b commit bafbfd0

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

symfony/console/4.2/bin/console

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ use Symfony\Component\Debug\Debug;
77

88
set_time_limit(0);
99

10-
require __DIR__.'/../src/bootstrap.php';
10+
[$env, $debug] = require __DIR__.'/../src/bootstrap.php';
1111

1212
if (!class_exists(Application::class)) {
1313
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
1414
}
1515

16-
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
17-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
18-
1916
if ($debug) {
2017
umask(0000);
2118

symfony/framework-bundle/4.2/public/index.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
use Symfony\Component\Debug\Debug;
55
use Symfony\Component\HttpFoundation\Request;
66

7-
require __DIR__.'/../src/bootstrap.php';
8-
9-
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
10-
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ('prod' !== $env));
7+
[$env, $debug] = require __DIR__.'/../src/bootstrap.php';
118

129
if ($debug) {
1310
umask(0000);

symfony/framework-bundle/4.2/src/bootstrap.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
use Symfony\Component\Dotenv\Dotenv;
66

7-
if (class_exists(Dotenv::class)) {
8-
(new Dotenv())->loadForEnv($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev', __DIR__.'/../.env');
9-
} elseif (!isset($_SERVER['APP_ENV']) && !isset($_ENV['APP_ENV'])) {
7+
$envFromEnv = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null;
8+
$env = $envFromEnv ?? 'dev';
9+
$prod = 'prod' === $env;
10+
11+
if (!$prod && class_exists(Dotenv::class)) {
12+
(new Dotenv())->loadForEnv($env, __DIR__.'/../.env');
13+
} elseif (null === $envFromEnv) {
1014
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
1115
}
16+
17+
return [$env, (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? (!$prod))];

0 commit comments

Comments
 (0)
0