index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @package Grav.Core
  4. *
  5. * @copyright Copyright (c) 2015 - 2024 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 (PHP_SAPI === 'cli-server') {
  12. $symfony_server = stripos(getenv('_'), 'symfony') !== false || stripos($_SERVER['SERVER_SOFTWARE'] ?? '', 'symfony') !== false || stripos($_ENV['SERVER_SOFTWARE'] ?? '', 'symfony') !== false;
  13. if (!isset($_SERVER['PHP_CLI_ROUTER']) && !$symfony_server) {
  14. die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
  15. }
  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. // Set timezone to default, falls back to system if php.ini not set
  25. date_default_timezone_set(@date_default_timezone_get());
  26. // Set internal encoding.
  27. @ini_set('default_charset', 'UTF-8');
  28. mb_internal_encoding('UTF-8');
  29. use Grav\Common\Grav;
  30. use RocketTheme\Toolbox\Event\Event;
  31. // Get the Grav instance
  32. $grav = Grav::instance(array('loader' => $loader));
  33. // Process the page
  34. try {
  35. $grav->process();
  36. } catch (\Error|\Exception $e) {
  37. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  38. throw $e;
  39. }