Changeset View
Changeset View
Standalone View
Standalone View
config/bootstrap.php
- This file was added.
1 | <?php | ||||
---|---|---|---|---|---|
2 | | ||||
3 | use Symfony\Component\Dotenv\Dotenv; | ||||
4 | | ||||
5 | require dirname(__DIR__).'/vendor/autoload.php'; | ||||
6 | | ||||
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 | $path = dirname(__DIR__).'/.env'; | ||||
16 | $dotenv = new Dotenv(); | ||||
17 | | ||||
18 | // load all the .env files | ||||
19 | if (method_exists($dotenv, 'loadEnv')) { | ||||
20 | $dotenv->loadEnv($path); | ||||
21 | } else { | ||||
22 | // fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added) | ||||
23 | | ||||
24 | if (file_exists($path) || !file_exists($p = "$path.dist")) { | ||||
25 | $dotenv->load($path); | ||||
26 | } else { | ||||
27 | $dotenv->load($p); | ||||
28 | } | ||||
29 | | ||||
30 | if (null === $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) { | ||||
31 | $dotenv->populate(array('APP_ENV' => $env = 'dev')); | ||||
32 | } | ||||
33 | | ||||
34 | if ('test' !== $env && file_exists($p = "$path.local")) { | ||||
35 | $dotenv->load($p); | ||||
36 | $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env; | ||||
37 | } | ||||
38 | | ||||
39 | if (file_exists($p = "$path.$env")) { | ||||
40 | $dotenv->load($p); | ||||
41 | } | ||||
42 | | ||||
43 | if (file_exists($p = "$path.$env.local")) { | ||||
44 | $dotenv->load($p); | ||||
45 | } | ||||
46 | } | ||||
47 | } | ||||
48 | | ||||
49 | $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; | ||||
50 | $_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; | ||||
51 | $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; |