index.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use App\Kernel;
  3. use Symfony\Component\Debug\Debug;
  4. use Symfony\Component\Dotenv\Dotenv;
  5. use Symfony\Component\HttpFoundation\Request;
  6. require __DIR__.'/../vendor/autoload.php';
  7. // The check is to ensure we don't use .env in production
  8. if (!isset($_SERVER['APP_ENV'])) {
  9. if (!class_exists(Dotenv::class)) {
  10. throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
  11. }
  12. (new Dotenv())->load(__DIR__.'/../.env');
  13. }
  14. if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
  15. umask(0000);
  16. Debug::enable();
  17. }
  18. if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
  19. Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
  20. }
  21. if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
  22. Request::setTrustedHosts(explode(',', $trustedHosts));
  23. }
  24. $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));
  25. $request = Request::createFromGlobals();
  26. $response = $kernel->handle($request);
  27. $response->send();
  28. $kernel->terminate($request, $response);