index.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of GNU social - https://www.gnu.org/software/social
  4. *
  5. * GNU social is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GNU social is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * GNU social's true web entry point, bootstraps Symfony's configuration and instantiates our Kernel
  20. *
  21. * @package GNUsocial
  22. * @category Framework
  23. *
  24. * @author Hugo Sales <hugo@fc.up.pt>
  25. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. use App\CacheKernel;
  29. use App\Kernel;
  30. use Symfony\Component\ErrorHandler\Debug;
  31. use Symfony\Component\HttpFoundation\Request;
  32. require dirname(__DIR__) . '/config/bootstrap.php';
  33. if ($_SERVER['APP_DEBUG']) {
  34. umask(0000);
  35. Debug::enable();
  36. }
  37. if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
  38. Request::setTrustedProxies(\explode(',', $trustedProxies),
  39. Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
  40. }
  41. if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
  42. Request::setTrustedHosts([$trustedHosts]);
  43. }
  44. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  45. // Wrap the default Kernel with the CacheKernel one in 'prod' environment
  46. if ('prod' === $kernel->getEnvironment() || isset($_ENV['SOCIAL_USE_CACHE_KERNEL'])) {
  47. $kernel = new CacheKernel($kernel);
  48. }
  49. $request = Request::createFromGlobals();
  50. $response = $kernel->handle($request);
  51. $response->send();
  52. $kernel->terminate($request, $response);