2020-02-06 02:35:13 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-02-06 02:35:13 +00:00
|
|
|
namespace App\Console\Command;
|
|
|
|
|
2021-12-23 01:32:40 +00:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2020-02-06 02:35:13 +00:00
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
2021-12-23 01:32:40 +00:00
|
|
|
abstract class CommandAbstract extends Command
|
2020-02-06 02:35:13 +00:00
|
|
|
{
|
2022-09-16 23:59:46 +00:00
|
|
|
protected function runCommand(OutputInterface $output, string $command_name, array $command_args = []): int
|
2020-02-06 02:35:13 +00:00
|
|
|
{
|
2021-12-23 01:32:40 +00:00
|
|
|
$command = $this->getApplication()?->find($command_name);
|
|
|
|
if (null === $command) {
|
2022-09-16 23:59:46 +00:00
|
|
|
throw new \RuntimeException(sprintf('Command %s not found.', $command_name));
|
2021-12-23 01:32:40 +00:00
|
|
|
}
|
2020-02-06 02:35:13 +00:00
|
|
|
|
|
|
|
$input = new ArrayInput(['command' => $command_name] + $command_args);
|
|
|
|
$input->setInteractive(false);
|
|
|
|
|
2022-09-16 23:59:46 +00:00
|
|
|
return $command->run($input, $output);
|
2020-02-06 02:35:13 +00:00
|
|
|
}
|
|
|
|
}
|