bootstrap.php 1.2 KB

1234567891011121314151617181920212223
  1. <?php
  2. use Symfony\Component\Dotenv\Dotenv;
  3. require dirname(__DIR__).'/vendor/autoload.php';
  4. // Load cached env vars if the .env.local.php file exists
  5. // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
  6. 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'])) {
  7. foreach ($env as $k => $v) {
  8. $_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v);
  9. }
  10. } elseif (!class_exists(Dotenv::class)) {
  11. throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
  12. } else {
  13. // load all the .env files
  14. (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
  15. }
  16. $_SERVER += $_ENV;
  17. $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
  18. $_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
  19. $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';