Skip to content

Commit d88ab15

Browse files
Switch to the new Symfony .env structure
1 parent 8b846dc commit d88ab15

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

api/bin/console

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ if (!class_exists(Application::class)) {
1515
}
1616

1717
$input = new ArgvInput();
18-
if (null !== $_ENV['APP_ENV'] = $input->getParameterOption(['--env', '-e'], null, true)) {
19-
putenv('APP_ENV='.$_ENV['APP_ENV']);
20-
// force loading .env files when --env is defined
21-
$_SERVER['APP_ENV'] = null;
18+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
19+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
2220
}
2321

2422
if ($input->hasParameterOption('--no-debug', true)) {

api/config/bootstrap.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
require dirname(__DIR__).'/vendor/autoload.php';
66

7-
if (!array_key_exists('APP_ENV', $_SERVER)) {
8-
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] ?? null;
9-
}
10-
11-
if ('prod' !== $_SERVER['APP_ENV']) {
12-
if (!class_exists(Dotenv::class)) {
13-
throw new RuntimeException('The "APP_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
14-
}
15-
7+
// Load cached env vars if the .env.local.php file exists
8+
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
9+
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
10+
$_SERVER += $env;
11+
$_ENV += $env;
12+
} elseif (!class_exists(Dotenv::class)) {
13+
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
14+
} else {
15+
// load all the .env files
1616
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
1717
}
1818

19-
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $_SERVER['APP_ENV'] ?: $_ENV['APP_ENV'] ?: 'dev';
19+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
2020
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
2121
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

api/src/Kernel.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ class Kernel extends BaseKernel
1515

1616
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
1717

18-
public function getCacheDir()
19-
{
20-
return $this->getProjectDir().'/var/cache/'.$this->environment;
21-
}
22-
23-
public function getLogDir()
24-
{
25-
return $this->getProjectDir().'/var/log';
26-
}
27-
2818
public function registerBundles()
2919
{
3020
$contents = require $this->getProjectDir().'/config/bundles.php';

0 commit comments

Comments
 (0)