webman 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env php
  2. <?php
  3. use Webman\Config;
  4. use Webman\Console\Command;
  5. use Webman\Console\Util;
  6. use support\Container;
  7. require_once __DIR__ . '/vendor/autoload.php';
  8. if (!in_array($argv[1] ?? '', ['start', 'restart', 'stop', 'status', 'reload', 'connections'])) {
  9. require_once __DIR__ . '/support/bootstrap.php';
  10. } else {
  11. if (class_exists('Support\App')) {
  12. Support\App::loadAllConfig(['route']);
  13. } else {
  14. Config::reload(config_path(), ['route', 'container']);
  15. }
  16. }
  17. $cli = new Command();
  18. $cli->setName('webman cli');
  19. $cli->installInternalCommands();
  20. if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) {
  21. $cli->installCommands($command_path);
  22. }
  23. foreach (config('plugin', []) as $firm => $projects) {
  24. if (isset($projects['app'])) {
  25. if ($command_str = Util::guessPath(base_path() . "/plugin/$firm", 'command')) {
  26. $command_path = base_path() . "/plugin/$firm/$command_str";
  27. $cli->installCommands($command_path, "plugin\\$firm\\$command_str");
  28. }
  29. }
  30. foreach ($projects as $name => $project) {
  31. if (!is_array($project)) {
  32. continue;
  33. }
  34. foreach ($project['command'] ?? [] as $class_name) {
  35. $reflection = new \ReflectionClass($class_name);
  36. if ($reflection->isAbstract()) {
  37. continue;
  38. }
  39. $properties = $reflection->getStaticProperties();
  40. $name = $properties['defaultName'];
  41. if (!$name) {
  42. throw new RuntimeException("Command {$class_name} has no defaultName");
  43. }
  44. $description = $properties['defaultDescription'] ?? '';
  45. $command = Container::get($class_name);
  46. $command->setName($name)->setDescription($description);
  47. $cli->add($command);
  48. }
  49. }
  50. }
  51. $cli->run();