InfoCommand.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Devtool;
  12. use Hyperf\Command\Annotation\Command;
  13. use Symfony\Component\Console\Command\Command as SymfonyCommand;
  14. use Symfony\Component\Console\Input\InputArgument;
  15. use Symfony\Component\Console\Input\InputInterface;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. #[Command]
  18. class InfoCommand extends SymfonyCommand
  19. {
  20. public function __construct(private Info $info)
  21. {
  22. parent::__construct('info');
  23. }
  24. protected function configure()
  25. {
  26. $this->setDescription('Dump the server info.')->addArgument('type', InputArgument::REQUIRED);
  27. }
  28. protected function execute(InputInterface $input, OutputInterface $output): int
  29. {
  30. $type = $input->getArgument('type');
  31. if (! $this->info->has($type)) {
  32. $output->writeln(sprintf('<error>Error</error> Info type [%s] not exist.', $type));
  33. return 0;
  34. }
  35. $adapter = $this->info->get($type);
  36. $adapter->execute($input, $output);
  37. return 0;
  38. }
  39. }