index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @package Grav.Core
  4. *
  5. * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav;
  9. \define('GRAV_REQUEST_TIME', microtime(true));
  10. \define('GRAV_PHP_MIN', '7.3.6');
  11. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  12. die(sprintf('You are running PHP %s, but Grav needs at least <strong>PHP %s</strong> to run.', $ver, $req));
  13. }
  14. if (PHP_SAPI === 'cli-server') {
  15. $symfony_server = stripos(getenv('_'), 'symfony') !== false || stripos($_SERVER['SERVER_SOFTWARE'] ?? '', 'symfony') !== false || stripos($_ENV['SERVER_SOFTWARE'] ?? '', 'symfony') !== false;
  16. if (!isset($_SERVER['PHP_CLI_ROUTER']) && !$symfony_server) {
  17. die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
  18. }
  19. }
  20. // Set timezone to default, falls back to system if php.ini not set
  21. date_default_timezone_set(@date_default_timezone_get());
  22. // Set internal encoding.
  23. if (!\extension_loaded('mbstring')) {
  24. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  25. }
  26. @ini_set('default_charset', 'UTF-8');
  27. mb_internal_encoding('UTF-8');
  28. // Ensure vendor libraries exist
  29. $autoload = __DIR__ . '/vendor/autoload.php';
  30. if (!is_file($autoload)) {
  31. die('Please run: <i>bin/grav install</i>');
  32. }
  33. // Register the auto-loader.
  34. $loader = require $autoload;
  35. use Grav\Common\Grav;
  36. use RocketTheme\Toolbox\Event\Event;
  37. // Get the Grav instance
  38. $grav = Grav::instance(
  39. array(
  40. 'loader' => $loader
  41. )
  42. );
  43. // Process the page
  44. try {
  45. $grav->process();
  46. } catch (\Error $e) {
  47. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  48. throw $e;
  49. } catch (\Exception $e) {
  50. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  51. throw $e;
  52. }