web/app.php line 71

Open in your IDE?
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\Debug\Debug;
  4. // Disable the PHAR stream wrapper as it is insecure
  5. if (in_array('phar'stream_get_wrappers())) {
  6.     stream_wrapper_unregister('phar');
  7. }
  8. // Ensure UTF-8 is used in string operations
  9. setlocale(LC_CTYPE'C.UTF-8');
  10. require __DIR__ '/../vendor/autoload.php';
  11. // Environment is taken from "SYMFONY_ENV" variable, if not set, defaults to "prod"
  12. $environment getenv('SYMFONY_ENV');
  13. if ($environment === false) {
  14.     $environment 'prod';
  15. }
  16. // Depending on the SYMFONY_DEBUG environment variable, tells whether Symfony should be loaded with debugging.
  17. // If not set, or "", it is auto activated if in "dev" environment.
  18. if (($useDebugging getenv('SYMFONY_DEBUG')) === false || $useDebugging === '') {
  19.     $useDebugging $environment === 'dev';
  20. }
  21. if ($useDebugging) {
  22.     Debug::enable();
  23. }
  24. $kernel = new AppKernel($environment$useDebugging);
  25. // Depending on the SYMFONY_HTTP_CACHE environment variable, tells whether the internal HTTP Cache mechanism is to be used.
  26. // Recommendation is to use Varnish over this, for performance and being able to setup cluster if you need to.
  27. // If not set, or "", it is auto activated if _not_ in "dev" environment.
  28. if (($useHttpCache getenv('SYMFONY_HTTP_CACHE')) === false || $useHttpCache === '') {
  29.     $useHttpCache $environment !== 'dev';
  30. }
  31. // Load internal HTTP Cache, aka Symfony Proxy, if enabled
  32. if ($useHttpCache) {
  33.     $kernel = new AppCache($kernel);
  34.     // Needed when using Synfony proxy, see: http://symfony.com/doc/3.4/reference/configuration/framework.html#http-method-override
  35.     Request::enableHttpMethodParameterOverride();
  36. }
  37. $request Request::createFromGlobals();
  38. // Deny request if it contains the frontcontroller script ie. http://example.com/app.php
  39. $frontControllerScript preg_quote(basename($request->server->get('SCRIPT_FILENAME')));
  40. if (preg_match("<^/([^/]+/)?$frontControllerScript([/?#]|$)>"$request->getRequestUri(), $matches) === 1) {
  41.     http_response_code(400);
  42.     echo('<html><head><title>400 Bad Request</title></head><body><h1>400 Bad Request</h1></center></body></html>');
  43.     die;
  44. }
  45. // If behind one or more trusted proxies, you can set them in SYMFONY_TRUSTED_PROXIES environment variable.
  46. // !! Proxies here refers to load balancers, TLS/Reverse proxies and so on. Which Symfony need to know about to
  47. // work correctly: identify https, allow Varnish to lookup fragment & user hash routes, get correct client ip, ...
  48. //
  49. // NOTE: You'll potentially need to customize these lines for your proxy depending on which forward headers to use!
  50. // SEE: https://symfony.com/doc/3.4/deployment/proxies.html
  51. if ($trustedProxies getenv('SYMFONY_TRUSTED_PROXIES')) {
  52.     if ($trustedProxies === 'TRUST_REMOTE') {
  53.         Request::setTrustedProxies([$request->server->get('REMOTE_ADDR')], Request::HEADER_X_FORWARDED_ALL);
  54.     } else {
  55.         Request::setTrustedProxies(explode(','$trustedProxies), Request::HEADER_X_FORWARDED_ALL);
  56.     }
  57. }
  58. $response $kernel->handle($request);
  59. $response->send();
  60. $kernel->terminate($request$response);