<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
use App\Kernel;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\HttpFoundation\Request;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
function _dd ($var) {
file_put_contents('dump.txt', str_replace('\/', '/', json_encode($var, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)) . "\n\n", FILE_APPEND);
}
if ($context['APP_ENV'] !== 'prod' && !in_array($_SERVER['REMOTE_ADDR'], ['::1', '127.0.0.1', '195.150.52.166'])) {
if (!($context['APP_TESTING'] ?? 0)) {
header('HTTP/1.0 403');
exit;
}
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts(explode(',', $trustedHosts));
}
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
$configAppLocation = '/config/packages/config_app.yaml';
if (!file_exists($kernel->getProjectDir() . $configAppLocation)) {
throw new \Exception(
' >> Missing application config file: ' . $kernel->getProjectDir() . $configAppLocation
);
}
$parsedConfigApp = Yaml::parseFile($kernel->getProjectDir() . $configAppLocation);
if (
!isset($parsedConfigApp['parameters']['app.web.dir']) ||
!isset($parsedConfigApp['parameters']['app.web.media_dir'])
) {
throw new \Exception(
' >> Missing key "app.web.dir" and/or "app.web.media_dir" under "parameters" in '
. $kernel->getProjectDir() . $configAppLocation
);
}
define('__APP_DIR__', $kernel->getProjectDir());
define('__WEB_DIR__', $kernel->getProjectDir() . '/' . $parsedConfigApp['parameters']['app.web.dir']);
define('__MEDIA_DIR__', __WEB_DIR__ . '/' . $parsedConfigApp['parameters']['app.web.media_dir']);
if ($context['APP_ENV'] !== 'prod') {
// for web-profiler symfony
if ($_ENV['TRUSTED_ORIGINS'] ?? false) {
header("Access-Control-Allow-Origin: " . $_ENV['TRUSTED_ORIGINS']);
}
if ($_ENV['TRUSTED_HEADRES'] ?? false && $_SERVER['REQUEST_METHOD'] == "OPTIONS") {
header("Access-Control-Allow-Headers: " . $_ENV['TRUSTED_HEADRES']);
}
}
return $kernel;
};