grav 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env php
  2. <?php
  3. use Grav\Common\Composer;
  4. use Grav\Common\Grav;
  5. use League\CLImate\CLImate;
  6. use Symfony\Component\Console\Application;
  7. \define('GRAV_CLI', true);
  8. \define('GRAV_REQUEST_TIME', microtime(true));
  9. if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
  10. // Before we can even start, we need to run composer first
  11. require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
  12. $composer = Composer::getComposerExecutor();
  13. echo "Preparing to install vendor dependencies...\n\n";
  14. echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install');
  15. echo "\n\n";
  16. }
  17. $autoload = require __DIR__ . '/../vendor/autoload.php';
  18. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  19. exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
  20. }
  21. if (!ini_get('date.timezone')) {
  22. date_default_timezone_set('UTC');
  23. }
  24. // Set internal encoding.
  25. if (!\extension_loaded('mbstring')) {
  26. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  27. }
  28. @ini_set('default_charset', 'UTF-8');
  29. mb_internal_encoding('UTF-8');
  30. $climate = new League\CLImate\CLImate;
  31. $climate->arguments->add([
  32. 'environment' => [
  33. 'prefix' => 'e',
  34. 'longPrefix' => 'env',
  35. 'description' => 'Configuration Environment',
  36. 'defaultValue' => 'localhost'
  37. ]
  38. ]);
  39. $climate->arguments->parse();
  40. // Set up environment based on params.
  41. $environment = $climate->arguments->get('environment');
  42. $grav = Grav::instance(array('loader' => $autoload));
  43. $grav->setup($environment);
  44. if (!file_exists(GRAV_ROOT . '/index.php')) {
  45. exit('FATAL: Must be run from ROOT directory of Grav!');
  46. }
  47. $app = new Application('Grav CLI Application', GRAV_VERSION);
  48. $app->addCommands(array(
  49. new \Grav\Console\Cli\InstallCommand(),
  50. new \Grav\Console\Cli\ComposerCommand(),
  51. new \Grav\Console\Cli\SandboxCommand(),
  52. new \Grav\Console\Cli\CleanCommand(),
  53. new \Grav\Console\Cli\ClearCacheCommand(),
  54. new \Grav\Console\Cli\BackupCommand(),
  55. new \Grav\Console\Cli\NewProjectCommand(),
  56. new \Grav\Console\Cli\SchedulerCommand(),
  57. new \Grav\Console\Cli\SecurityCommand(),
  58. new \Grav\Console\Cli\LogViewerCommand(),
  59. new \Grav\Console\Cli\YamlLinterCommand(),
  60. ));
  61. $app->run();