webman 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. foreach (['', '/app'] as $app) {
  26. if ($command_str = Util::guessPath(base_path() . "/plugin/$firm{$app}", 'command')) {
  27. $command_path = base_path() . "/plugin/$firm{$app}/$command_str";
  28. $cli->installCommands($command_path, "plugin\\$firm" . str_replace('/', '\\', $app) . "\\$command_str");
  29. }
  30. }
  31. }
  32. foreach ($projects as $name => $project) {
  33. if (!is_array($project)) {
  34. continue;
  35. }
  36. foreach ($project['command'] ?? [] as $class_name) {
  37. $reflection = new \ReflectionClass($class_name);
  38. if ($reflection->isAbstract()) {
  39. continue;
  40. }
  41. $properties = $reflection->getStaticProperties();
  42. $name = $properties['defaultName'];
  43. if (!$name) {
  44. throw new RuntimeException("Command {$class_name} has no defaultName");
  45. }
  46. $description = $properties['defaultDescription'] ?? '';
  47. $command = Container::get($class_name);
  48. $command->setName($name)->setDescription($description);
  49. $cli->add($command);
  50. }
  51. }
  52. }
  53. $cli->run();