router.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @package Grav\Core
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. if (PHP_SAPI !== 'cli-server') {
  9. die('This script cannot be run from browser. Run it from a CLI.');
  10. }
  11. $_SERVER['PHP_CLI_ROUTER'] = true;
  12. if (is_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_NAME'])) {
  13. return false;
  14. }
  15. $grav_index = 'index.php';
  16. /* Check the GRAV_BASEDIR environment variable and use if set */
  17. $grav_basedir = getenv('GRAV_BASEDIR') ?: '';
  18. if ($grav_basedir) {
  19. $grav_index = ltrim($grav_basedir, '/') . DIRECTORY_SEPARATOR . $grav_index;
  20. $grav_basedir = DIRECTORY_SEPARATOR . trim($grav_basedir, DIRECTORY_SEPARATOR);
  21. define('GRAV_ROOT', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()) . $grav_basedir);
  22. }
  23. $_SERVER = array_merge($_SERVER, $_ENV);
  24. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . $grav_basedir .DIRECTORY_SEPARATOR . 'index.php';
  25. $_SERVER['SCRIPT_NAME'] = $grav_basedir . DIRECTORY_SEPARATOR . 'index.php';
  26. $_SERVER['PHP_SELF'] = $grav_basedir . DIRECTORY_SEPARATOR . 'index.php';
  27. error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);
  28. require $grav_index;