bootstrap.php 1.3 KB

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