public/index.php line 59

Open in your IDE?
  1. <?php
  2. use App\CacheKernel;
  3. use App\Kernel;
  4. use Symfony\Component\Dotenv\Dotenv;
  5. use Symfony\Component\ErrorHandler\Debug;
  6. use Symfony\Component\HttpFoundation\Request;
  7. # mainly for on-the-fly thumbnail generation via LiipImagine
  8. ini_set('memory_limit', '256M');
  9. date_default_timezone_set('UTC');
  10. require dirname(__DIR__).'/vendor/autoload.php';
  11. // @NOTE: Must be set BEFORE bootEnv(), so that Dotenv's populate() sees it in $_SERVER,
  12. // copies it into $_ENV, and then skips the default value from .env.prod.
  13. // This ensures %env(SESSION_COOKIE_DOMAIN)% resolves to the correct domain for this front controller.
  14. // Since APP_ENV isn't available yet, the check for the environment can only take place _after_
  15. // bootEnv has been called!
  16. $_SERVER['SESSION_COOKIE_DOMAIN'] = '.joboo.de';
  17. (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
  18. if ($_SERVER['APP_DEBUG']) {
  19. umask(0000);
  20. Debug::enable();
  21. }
  22. $kernel = new CacheKernel(new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']));
  23. Request::enableHttpMethodParameterOverride();
  24. $request = Request::createFromGlobals();
  25. // @NOTE: bootEnv() copies $_SERVER vars into $_ENV as well (see Dotenv::populate()).
  26. // Symfony's EnvVarProcessor checks $_ENV *before* $_SERVER, so we must
  27. // unset the value from both superglobals for the removal to take effect.
  28. if ($_SERVER['APP_ENV'] !== 'prod') {
  29. unset(
  30. $_SERVER['SESSION_COOKIE_DOMAIN'],
  31. $_ENV['SESSION_COOKIE_DOMAIN']
  32. );
  33. }
  34. if ($_SERVER['APP_ENV'] === 'prod') {
  35. Request::setTrustedProxies(
  36. // This ensures that Symfony trusts all incoming requests (which are proxied to us via AWS ELBs).
  37. // Thus, Symfony will trust all "Forwarded" headers
  38. // ($_SERVER['HTTP_X_FORWARDED_PROTO'], $_SERVER['HTTP_X_FORWARDED_PORT'], $_SERVER['HTTP_X_FORWARDED_FOR'])
  39. // and will create correct redirects, e.g. to an https location if we are on an https page.
  40. ['127.0.0.1', $request->server->get('REMOTE_ADDR'), '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'],
  41. // trust *all* "X-Forwarded-*" headers
  42. Request::HEADER_X_FORWARDED_AWS_ELB
  43. );
  44. }
  45. $response = $kernel->handle($request);
  46. $response->send();
  47. $kernel->terminate($request, $response);