<?php
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/vendor/autoload.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if (php_sapi_name() !== 'cli' && !isset($_GET['auth_disable'])) {
$user = $_SERVER['HTTP_BASIC_AUTH_USERNAME'];
$pass = $_SERVER['HTTP_BASIC_AUTH_PASSWORD'];
if ($user && $pass) {
$readUser = $_SERVER['PHP_AUTH_USER'] ?? null;
$readPw = $_SERVER['PHP_AUTH_PW'] ?? null;
if ($user !== $readUser || $pass !== $readPw) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Please, provide correct credentials';
return;
}
}
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? []) {
Request::setTrustedProxies(
explode(',', $trustedProxies),
Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT
);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);