CommandService.php 801 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Core\Service;
  4. use Closure;
  5. use think\exception\ClassNotFoundException;
  6. use function SixShop\Core\extension_name_list;
  7. readonly class CommandService
  8. {
  9. public function __construct(private AutoloadService $autoloadService)
  10. {
  11. }
  12. public function init(Closure $closure): void
  13. {
  14. $commands = [];
  15. foreach (extension_name_list() as $extensionName) {
  16. try {
  17. $extension = $this->autoloadService->getExtension($extensionName);
  18. } catch (ClassNotFoundException $_) {
  19. continue;
  20. }
  21. if (!$extension->available()) {
  22. continue;
  23. }
  24. $commands += $extension->getCommands();
  25. }
  26. $closure($commands);
  27. }
  28. }