grav 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $climate = new League\CLImate\CLImate;
  22. $climate->arguments->add([
  23. 'environment' => [
  24. 'prefix' => 'e',
  25. 'longPrefix' => 'env',
  26. 'description' => 'Configuration Environment',
  27. 'defaultValue' => 'localhost'
  28. ]
  29. ]);
  30. $climate->arguments->parse();
  31. // Set up environment based on params.
  32. $environment = $climate->arguments->get('environment');
  33. $grav = Grav::instance(array('loader' => $autoload));
  34. $grav->setup($environment);
  35. if (!ini_get('date.timezone')) {
  36. date_default_timezone_set('UTC');
  37. }
  38. if (!file_exists(GRAV_ROOT . '/index.php')) {
  39. exit('FATAL: Must be run from ROOT directory of Grav!');
  40. }
  41. $app = new Application('Grav CLI Application', GRAV_VERSION);
  42. $app->addCommands(array(
  43. new \Grav\Console\Cli\InstallCommand(),
  44. new \Grav\Console\Cli\ComposerCommand(),
  45. new \Grav\Console\Cli\SandboxCommand(),
  46. new \Grav\Console\Cli\CleanCommand(),
  47. new \Grav\Console\Cli\ClearCacheCommand(),
  48. new \Grav\Console\Cli\BackupCommand(),
  49. new \Grav\Console\Cli\NewProjectCommand(),
  50. new \Grav\Console\Cli\SchedulerCommand(),
  51. new \Grav\Console\Cli\SecurityCommand(),
  52. new \Grav\Console\Cli\LogViewerCommand(),
  53. new \Grav\Console\Cli\YamlLinterCommand(),
  54. ));
  55. $app->run();