Console.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Command;
  12. use Closure;
  13. use function Hyperf\Support\make;
  14. use function Hyperf\Tappable\tap;
  15. class Console
  16. {
  17. public const ROUTE = BASE_PATH . '/config/console.php';
  18. /**
  19. * @var ClosureCommand[]
  20. */
  21. protected static $commands = [];
  22. public static function command(string $signature, Closure $command): ClosureCommand
  23. {
  24. return tap(make(ClosureCommand::class, [
  25. 'signature' => $signature,
  26. 'closure' => $command,
  27. ]), static function ($handler) {
  28. $handlerId = spl_object_hash($handler);
  29. self::$commands[$handlerId] = $handler;
  30. });
  31. }
  32. /**
  33. * @return ClosureCommand[]
  34. */
  35. public static function getCommands(): array
  36. {
  37. return self::$commands;
  38. }
  39. }