命令行配置

AutoLoader配置

  1. <?php declare(strict_types=1);
  2. namespace Swoft\Console;
  3. use function dirname;
  4. use Swoft\Console\Router\Router;
  5. use Swoft\Helper\ComposerJSON;
  6. use Swoft\SwoftComponent;
  7. /**
  8. * class AutoLoader
  9. * @since 2.0
  10. */
  11. final class AutoLoader extends SwoftComponent
  12. {
  13. /**
  14. * @return bool
  15. */
  16. public function enable(): bool
  17. {
  18. return true;
  19. }
  20. /**
  21. * Get namespace and dirs
  22. *
  23. * @return array
  24. */
  25. public function getPrefixDirs(): array
  26. {
  27. return [
  28. __NAMESPACE__ => __DIR__,
  29. ];
  30. }
  31. /**
  32. * Metadata information for the component
  33. *
  34. * @return array
  35. */
  36. public function metadata(): array
  37. {
  38. $jsonFile = dirname(__DIR__) . '/composer.json';
  39. return ComposerJSON::open($jsonFile)->getMetadata();
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function beans(): array
  45. {
  46. return [
  47. 'cliApp' => [
  48. 'class' => Application::class,
  49. ],
  50. 'cliRouter' => [
  51. 'class' => Router::class,
  52. ],
  53. 'cliDispatcher' => [
  54. 'class' => ConsoleDispatcher::class,
  55. ],
  56. ];
  57. }
  58. }