MakeDirectoryCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Commands;
  3. use App\AppService;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use YdbPlatform\Ydb\Ydb;
  9. class MakeDirectoryCommand extends Command
  10. {
  11. /**
  12. * @var string
  13. */
  14. protected static $defaultName = 'mkdir';
  15. /**
  16. * @var AppService
  17. */
  18. protected $appService;
  19. public function __construct()
  20. {
  21. $this->appService = new AppService;
  22. parent::__construct();
  23. }
  24. protected function configure()
  25. {
  26. $this->setDescription('Make a directory.');
  27. $this->addArgument('dirname', InputArgument::REQUIRED, 'The directory name.');
  28. }
  29. /**
  30. * @param InputInterface $input
  31. * @param OutputInterface $output
  32. * @return int
  33. */
  34. protected function execute(InputInterface $input, OutputInterface $output)
  35. {
  36. $dirname = $input->getArgument('dirname');
  37. $ydb = $this->appService->initYdb();
  38. $result = $ydb->retry(function (Ydb $ydb) use ($output, $dirname) {
  39. $scheme = $ydb->scheme();
  40. return $scheme->makeDirectory($dirname);
  41. }, true);
  42. $output->writeln(json_encode($result, 480));
  43. return Command::SUCCESS;
  44. }
  45. }