AbstractDatabaseCommand.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\CLI\Command\Db;
  4. use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand;
  5. use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
  6. use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\Lock\LockFactory;
  9. use Symfony\Component\Process\PhpExecutableFinder;
  10. abstract class AbstractDatabaseCommand extends AbstractLockedCommand
  11. {
  12. private ProcessRunnerInterface $processRunner;
  13. private string $phpBinary;
  14. public function __construct(
  15. LockFactory $locker,
  16. ProcessRunnerInterface $processRunner,
  17. PhpExecutableFinder $phpFinder
  18. ) {
  19. parent::__construct($locker);
  20. $this->processRunner = $processRunner;
  21. $this->phpBinary = $phpFinder->find(false) ?: 'php';
  22. }
  23. protected function runPhpCommand(OutputInterface $output, array $command): void
  24. {
  25. $command = [$this->phpBinary, ...$command, '--no-interaction'];
  26. $this->processRunner->run($output, $command);
  27. }
  28. protected function getLockConfig(): LockedCommandConfig
  29. {
  30. return LockedCommandConfig::blocking($this->getName());
  31. }
  32. }