2020-03-11 04:04:22 +09:00
|
|
|
<?php
|
|
|
|
|
2020-08-04 05:45:00 +09:00
|
|
|
use App\Core\ModuleManager;
|
2020-03-11 04:04:22 +09:00
|
|
|
use Symfony\Component\Dotenv\Dotenv;
|
|
|
|
|
2020-08-04 05:45:00 +09:00
|
|
|
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
|
2020-03-11 04:04:22 +09:00
|
|
|
|
|
|
|
// Load cached env vars if the .env.local.php file exists
|
|
|
|
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
|
2020-03-16 06:21:11 +09:00
|
|
|
if (\is_array($env = @include dirname(__DIR__) . '/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
|
2020-03-11 04:04:22 +09:00
|
|
|
foreach ($env as $k => $v) {
|
|
|
|
$_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v);
|
|
|
|
}
|
2020-03-16 06:21:11 +09:00
|
|
|
} elseif (!\class_exists(Dotenv::class)) {
|
2020-03-11 04:04:22 +09:00
|
|
|
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
|
|
|
|
} else {
|
|
|
|
// load all the .env files
|
2020-06-08 21:04:20 +09:00
|
|
|
(new Dotenv())->loadEnv(\dirname(__DIR__) . '/.env');
|
2020-03-11 04:04:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$_SERVER += $_ENV;
|
2020-03-16 06:21:11 +09:00
|
|
|
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
|
2020-03-11 04:04:22 +09:00
|
|
|
$_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';
|
2020-08-04 05:45:00 +09:00
|
|
|
|
|
|
|
ModuleManager::setLoader($loader);
|