index.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @package Grav.Core
  4. *
  5. * @copyright Copyright (C) 2015 - 2018 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.1.3');
  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' && !isset($_SERVER['PHP_CLI_ROUTER'])) {
  15. die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
  16. }
  17. // Set timezone to default, falls back to system if php.ini not set
  18. date_default_timezone_set(@date_default_timezone_get());
  19. // Set internal encoding.
  20. if (!\extension_loaded('mbstring')) {
  21. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  22. }
  23. @ini_set('default_charset', 'UTF-8');
  24. mb_internal_encoding('UTF-8');
  25. // Ensure vendor libraries exist
  26. $autoload = __DIR__ . '/vendor/autoload.php';
  27. if (!is_file($autoload)) {
  28. die('Please run: <i>bin/grav install</i>');
  29. }
  30. // Register the auto-loader.
  31. $loader = require $autoload;
  32. use Grav\Common\Grav;
  33. use RocketTheme\Toolbox\Event\Event;
  34. // Get the Grav instance
  35. $grav = Grav::instance(
  36. array(
  37. 'loader' => $loader
  38. )
  39. );
  40. // Process the page
  41. try {
  42. $grav->process();
  43. } catch (\Error $e) {
  44. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  45. throw $e;
  46. } catch (\Exception $e) {
  47. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  48. throw $e;
  49. }