index.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @package Grav.Core
  4. *
  5. * @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav;
  9. define('GRAV_PHP_MIN', '5.5.9');
  10. // Ensure vendor libraries exist
  11. $autoload = __DIR__ . '/vendor/autoload.php';
  12. if (!is_file($autoload)) {
  13. die("Please run: <i>bin/grav install</i>");
  14. }
  15. if (PHP_SAPI == 'cli-server') {
  16. if (!isset($_SERVER['PHP_CLI_ROUTER'])) {
  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. use Grav\Common\Grav;
  21. use RocketTheme\Toolbox\Event\Event;
  22. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  23. die(sprintf('You are running PHP %s, but Grav needs at least <strong>PHP %s</strong> to run.', $ver, $req));
  24. }
  25. // Register the auto-loader.
  26. $loader = require_once $autoload;
  27. // Set timezone to default, falls back to system if php.ini not set
  28. date_default_timezone_set(@date_default_timezone_get());
  29. // Set internal encoding if mbstring loaded
  30. if (!extension_loaded('mbstring')) {
  31. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  32. }
  33. mb_internal_encoding('UTF-8');
  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 (\Exception $e) {
  44. $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
  45. throw $e;
  46. }