Initial commit Proches de moi server side code:
[Project_proches_de_moi-server.git] / public / index.php
1 <?php
2
3 use App\Kernel;
4 use Symfony\Component\Debug\Debug;
5 use Symfony\Component\Dotenv\Dotenv;
6 use Symfony\Component\HttpFoundation\Request;
7
8 require __DIR__.'/../vendor/autoload.php';
9
10 // The check is to ensure we don't use .env in production
11 if (!isset($_SERVER['APP_ENV'])) {
12 if (!class_exists(Dotenv::class)) {
13 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.');
14 }
15 (new Dotenv())->load(__DIR__.'/../.env');
16 }
17
18 $env = $_SERVER['APP_ENV'] ?? 'dev';
19 $debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
20
21 if ($debug) {
22 umask(0000);
23
24 Debug::enable();
25 }
26
27 if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
28 Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
29 }
30
31 if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
32 Request::setTrustedHosts(explode(',', $trustedHosts));
33 }
34
35 $kernel = new Kernel($env, $debug);
36 $request = Request::createFromGlobals();
37 $response = $kernel->handle($request);
38 $response->send();
39 $kernel->terminate($request, $response);