<?php
use App\CacheKernel;
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
# mainly for on-the-fly thumbnail generation via LiipImagine
ini_set('memory_limit', '256M');
date_default_timezone_set('UTC');
require dirname(__DIR__).'/vendor/autoload.php';
// @NOTE: Must be set BEFORE bootEnv(), so that Dotenv's populate() sees it in $_SERVER,
// copies it into $_ENV, and then skips the default value from .env.prod.
// This ensures %env(SESSION_COOKIE_DOMAIN)% resolves to the correct domain for this front controller.
// Since APP_ENV isn't available yet, the check for the environment can only take place _after_
// bootEnv has been called!
$_SERVER['SESSION_COOKIE_DOMAIN'] = '.joboo.de';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
$kernel = new CacheKernel(new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']));
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
// @NOTE: bootEnv() copies $_SERVER vars into $_ENV as well (see Dotenv::populate()).
// Symfony's EnvVarProcessor checks $_ENV *before* $_SERVER, so we must
// unset the value from both superglobals for the removal to take effect.
if ($_SERVER['APP_ENV'] !== 'prod') {
unset(
$_SERVER['SESSION_COOKIE_DOMAIN'],
$_ENV['SESSION_COOKIE_DOMAIN']
);
}
if ($_SERVER['APP_ENV'] === 'prod') {
Request::setTrustedProxies(
// This ensures that Symfony trusts all incoming requests (which are proxied to us via AWS ELBs).
// Thus, Symfony will trust all "Forwarded" headers
// ($_SERVER['HTTP_X_FORWARDED_PROTO'], $_SERVER['HTTP_X_FORWARDED_PORT'], $_SERVER['HTTP_X_FORWARDED_FOR'])
// and will create correct redirects, e.g. to an https location if we are on an https page.
['127.0.0.1', $request->server->get('REMOTE_ADDR'), '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'],
// trust *all* "X-Forwarded-*" headers
Request::HEADER_X_FORWARDED_AWS_ELB
);
}
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);