grav 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
  5. * @license MIT License; see LICENSE file for details.
  6. */
  7. use Grav\Common\Composer;
  8. use Grav\Common\Grav;
  9. use Grav\Console\Application\GravApplication;
  10. \define('GRAV_CLI', true);
  11. \define('GRAV_REQUEST_TIME', microtime(true));
  12. if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
  13. // Before we can even start, we need to run composer first
  14. require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
  15. $composer = Composer::getComposerExecutor();
  16. echo "Preparing to install vendor dependencies...\n\n";
  17. echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install');
  18. echo "\n\n";
  19. }
  20. $autoload = require __DIR__ . '/../vendor/autoload.php';
  21. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  22. exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
  23. }
  24. if (!ini_get('date.timezone')) {
  25. date_default_timezone_set('UTC');
  26. }
  27. // Set internal encoding.
  28. if (!\extension_loaded('mbstring')) {
  29. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  30. }
  31. @ini_set('default_charset', 'UTF-8');
  32. mb_internal_encoding('UTF-8');
  33. $grav = Grav::instance(array('loader' => $autoload));
  34. if (!file_exists(GRAV_ROOT . '/index.php')) {
  35. exit('FATAL: Must be run from ROOT directory of Grav!');
  36. }
  37. $app = new GravApplication('Grav CLI Application', GRAV_VERSION);
  38. $app->run();