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