-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
require dirname(__DIR__).'/vendor/autoload.php'; | ||
|
||
// Load cached env vars if the .env.local.php file exists | ||
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) | ||
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { | ||
$_SERVER += $env; | ||
$_ENV += $env; | ||
} elseif (!class_exists(Dotenv::class)) { | ||
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); | ||
} else { | ||
$path = dirname(__DIR__).'/.env'; | ||
$dotenv = new Dotenv(); | ||
|
||
// load all the .env files | ||
if (method_exists($dotenv, 'loadEnv')) { | ||
$dotenv->loadEnv($path); | ||
} else { | ||
// fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added) | ||
|
||
if (file_exists($path) || !file_exists($p = "$path.dist")) { | ||
$dotenv->load($path); | ||
} else { | ||
$dotenv->load($p); | ||
} | ||
|
||
if (null === $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) { | ||
$dotenv->populate(array('APP_ENV' => $env = 'dev')); | ||
} | ||
|
||
if ('test' !== $env && file_exists($p = "$path.local")) { | ||
$dotenv->load($p); | ||
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env; | ||
} | ||
|
||
if (file_exists($p = "$path.$env")) { | ||
$dotenv->load($p); | ||
} | ||
|
||
if (file_exists($p = "$path.$env.local")) { | ||
$dotenv->load($p); | ||
} | ||
} | ||
} | ||
|
||
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; | ||
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; | ||
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; |