index.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // Ensure vendor libraries exist
  18. $autoload = __DIR__ . '/vendor/autoload.php';
  19. if (!is_file($autoload)) {
  20. die('Please run: <i>bin/grav install</i>');
  21. }
  22. // Register the auto-loader.
  23. $loader = require $autoload;
  24. use Grav\Common\Grav;
  25. use RocketTheme\Toolbox\Event\Event;
  26. // Set timezone to default, falls back to system if php.ini not set
  27. date_default_timezone_set(@date_default_timezone_get());
  28. // Set internal encoding if mbstring loaded
  29. if (!\extension_loaded('mbstring')) {
  30. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  31. }
  32. mb_internal_encoding('UTF-8');
  33. // Get the Grav instance
  34. $grav = Grav::instance(
  35. array(
  36. 'loader' => $loader
  37. )
  38. );
  39. // Process the page
  40. try {
  41. $grav->process();
  42. } catch (\Error $e) {
  43. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  44. throw $e;
  45. } catch (\Exception $e) {
  46. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  47. throw $e;
  48. }