webman 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. use Dotenv\Dotenv;
  8. if (!Phar::running()) {
  9. chdir(__DIR__);
  10. }
  11. require_once __DIR__ . '/vendor/autoload.php';
  12. if (!$appConfigFile = config_path('app.php')) {
  13. throw new RuntimeException('Config file not found: app.php');
  14. }
  15. if (class_exists(Dotenv::class) && file_exists(run_path('.env'))) {
  16. if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
  17. Dotenv::createUnsafeImmutable(run_path())->load();
  18. } else {
  19. Dotenv::createMutable(run_path())->load();
  20. }
  21. }
  22. $appConfig = require $appConfigFile;
  23. if ($timezone = $appConfig['default_timezone'] ?? '') {
  24. date_default_timezone_set($timezone);
  25. }
  26. if ($errorReporting = $appConfig['error_reporting'] ?? '') {
  27. error_reporting($errorReporting);
  28. }
  29. if (!in_array($argv[1] ?? '', ['start', 'restart', 'stop', 'status', 'reload', 'connections'])) {
  30. require_once __DIR__ . '/support/bootstrap.php';
  31. } else {
  32. if (class_exists('Support\App')) {
  33. Support\App::loadAllConfig(['route']);
  34. } else {
  35. Config::reload(config_path(), ['route', 'container']);
  36. }
  37. }
  38. $cli = new Command();
  39. $cli->setName('webman cli');
  40. $cli->installInternalCommands();
  41. if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) {
  42. $cli->installCommands($command_path);
  43. }
  44. foreach (config('plugin', []) as $firm => $projects) {
  45. if (isset($projects['app'])) {
  46. foreach (['', '/app'] as $app) {
  47. if ($command_str = Util::guessPath(base_path() . "/plugin/$firm{$app}", 'command')) {
  48. $command_path = base_path() . "/plugin/$firm{$app}/$command_str";
  49. $cli->installCommands($command_path, "plugin\\$firm" . str_replace('/', '\\', $app) . "\\$command_str");
  50. }
  51. }
  52. }
  53. foreach ($projects as $name => $project) {
  54. if (!is_array($project)) {
  55. continue;
  56. }
  57. $project['command'] ??= [];
  58. array_walk($project['command'], [$cli, 'createCommandInstance']);
  59. }
  60. }
  61. $cli->run();