public/index.php line 76

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. use App\Kernel;
  11. use Sulu\Component\HttpKernel\SuluKernel;
  12. use Symfony\Component\Dotenv\Dotenv;
  13. use Symfony\Component\ErrorHandler\Debug;
  14. use Symfony\Component\HttpFoundation\Request;
  15. \defined('SULU_MAINTENANCE') || \define('SULU_MAINTENANCE', \getenv('SULU_MAINTENANCE') ?: false);
  16. // maintenance mode
  17. if (SULU_MAINTENANCE) {
  18. $maintenanceFilePath = __DIR__ . '/maintenance.php';
  19. // show maintenance mode and exit if no allowed IP is met
  20. if (require $maintenanceFilePath) {
  21. exit();
  22. }
  23. }
  24. require \dirname(__DIR__) . '/vendor/autoload.php';
  25. (new Dotenv())->bootEnv(\dirname(__DIR__) . '/.env');
  26. if ($_SERVER['APP_DEBUG']) {
  27. \umask(0000);
  28. Debug::enable();
  29. }
  30. if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
  31. Request::setTrustedProxies(\explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
  32. }
  33. if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
  34. Request::setTrustedHosts([$trustedHosts]);
  35. }
  36. $suluContext = SuluKernel::CONTEXT_WEBSITE;
  37. if (\preg_match('/^\/admin(\/|$)/', $_SERVER['REQUEST_URI'])) {
  38. $suluContext = SuluKernel::CONTEXT_ADMIN;
  39. }
  40. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], $suluContext);
  41. // Cache HTTP Sulu (pages) — bascule via APP_SITE_CACHE_ENABLED=0|1
  42. // Comment this line if you want to use the "varnish" http
  43. // caching strategy. See http://sulu.readthedocs.org/en/latest/cookbook/caching-with-varnish.html
  44. $siteCacheEnabled = filter_var(
  45. $_SERVER['APP_SITE_CACHE_ENABLED'] ?? false,
  46. \FILTER_VALIDATE_BOOLEAN
  47. );
  48. if (
  49. $siteCacheEnabled
  50. && 'dev' !== $_SERVER['APP_ENV']
  51. && SuluKernel::CONTEXT_WEBSITE === $suluContext
  52. ) {
  53. $kernel = $kernel->getHttpCache();
  54. }
  55. // When using the HttpCache, you need to call the method in your front controller
  56. // instead of relying on the configuration parameter
  57. // https://symfony.com/doc/3.4/reference/configuration/framework.html#http-method-override
  58. Request::enableHttpMethodParameterOverride();
  59. $request = Request::createFromGlobals();
  60. $response = $kernel->handle($request);
  61. $response->send();
  62. $kernel->terminate($request, $response);