WhoAmICommand.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Commands;
  3. use App\AppService;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use YdbPlatform\Ydb\Ydb;
  8. class WhoAmICommand extends Command
  9. {
  10. /**
  11. * @var string
  12. */
  13. protected static $defaultName = 'whoami';
  14. /**
  15. * @var AppService
  16. */
  17. protected $appService;
  18. public function __construct()
  19. {
  20. $this->appService = new AppService;
  21. parent::__construct();
  22. }
  23. protected function configure()
  24. {
  25. $this->setDescription('Get the WhoAmI information.');
  26. }
  27. /**
  28. * @param InputInterface $input
  29. * @param OutputInterface $output
  30. * @return int
  31. */
  32. protected function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. $ydb = $this->appService->initYdb();
  35. $result = $ydb->retry(function (Ydb $ydb) use ($output) {
  36. $discovery = $ydb->discovery();
  37. return $discovery->whoAmI();
  38. }, true);
  39. $output->writeln($result);
  40. return Command::SUCCESS;
  41. }
  42. }