index.php line 88

Open in your IDE?
  1. <?php
  2. use Eccube\Kernel;
  3. use Eccube\Service\SystemService;
  4. use Symfony\Component\ErrorHandler\Debug;
  5. use Dotenv\Dotenv;
  6. use Symfony\Component\HttpFoundation\Request;
  7. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
  8.     $_SERVER['HTTPS'] = 'on';
  9.     $_ENV['HTTPS'] = 'on';
  10. }
  11. // システム要件チェック
  12. if (version_compare(PHP_VERSION, '7.4.0') < 0) {
  13.     die('Your PHP installation is too old. EC-CUBE requires at least PHP 7.4.0. See the <a href="https://doc4.ec-cube.net/quickstart/requirement" target="_blank">system requirements</a> page for more information.');
  14. }
  15. $autoload = __DIR__.'/vendor/autoload.php';
  16. if (!file_exists($autoload) && !is_readable($autoload)) {
  17.     die('Composer is not installed.');
  18. }
  19. require $autoload;
  20. // The check is to ensure we don't use .env in production
  21. if (!isset($_SERVER['APP_ENV'])) {
  22.     if (!class_exists(Dotenv::class)) {
  23.         throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
  24.     }
  25.     if (file_exists(__DIR__.'/.env')) {
  26.         (Dotenv::createUnsafeMutable(__DIR__))->load();
  27.         if (strpos(getenv('DATABASE_URL'), 'sqlite') !== false && !extension_loaded('pdo_sqlite')) {
  28.             (Dotenv::createUnsafeMutable(__DIR__, '.env.install'))->load();
  29.         }
  30.     } else {
  31.         (Dotenv::createUnsafeMutable(__DIR__, '.env.install'))->load();
  32.     }
  33. }
  34. error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
  35. $env = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'dev';
  36. $debug = isset($_SERVER['APP_DEBUG']) ? $_SERVER['APP_DEBUG'] : ('prod' !== $env);
  37. if ($debug) {
  38.     umask(0000);
  39.     Debug::enable();
  40. }
  41. $trustedProxies = isset($_SERVER['TRUSTED_PROXIES']) ? $_SERVER['TRUSTED_PROXIES'] : false;
  42. if ($trustedProxies) {
  43.     Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
  44. }
  45. $trustedHosts = isset($_SERVER['TRUSTED_HOSTS']) ? $_SERVER['TRUSTED_HOSTS'] : false;
  46. if ($trustedHosts) {
  47.     Request::setTrustedHosts(explode(',', $trustedHosts));
  48. }
  49. $request = Request::createFromGlobals();
  50. $maintenanceFile = env('ECCUBE_MAINTENANCE_FILE_PATH', __DIR__.'/.maintenance');
  51. if (file_exists($maintenanceFile)) {
  52.     $pathInfo = \rawurldecode($request->getPathInfo());
  53.     $adminPath = env('ECCUBE_ADMIN_ROUTE', 'admin');
  54.     $adminPath = '/'.\trim($adminPath, '/').'/';
  55.     if (\strpos($pathInfo, $adminPath) !== 0) {
  56.         $maintenanceContents = file_get_contents($maintenanceFile);
  57.         $maintenanceToken = explode(':', $maintenanceContents)[1] ?? null;
  58.         $tokenInCookie = $request->cookies->get(SystemService::MAINTENANCE_TOKEN_KEY);
  59.         if ($tokenInCookie === null || $tokenInCookie !== $maintenanceToken) {
  60.             $locale = env('ECCUBE_LOCALE');
  61.             $templateCode = env('ECCUBE_TEMPLATE_CODE');
  62.             $baseUrl = \htmlspecialchars(\rawurldecode($request->getBaseUrl()), ENT_QUOTES);
  63.             header('HTTP/1.1 503 Service Temporarily Unavailable');
  64.             require __DIR__.'/maintenance.php';
  65.             return;
  66.         }
  67.     }
  68. }
  69. $kernel = new Kernel($env, $debug);
  70. $response = $kernel->handle($request);
  71. $response->send();
  72. $kernel->terminate($request, $response);