Получить экземпляр приложения, найти команды и выполнять их:
protected function configure()
{
$this->setName('clean');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = $this->getApplication();
$cleanRedisKeysCmd = $app->find('clean-redis-keys');
$cleanRedisKeysInput = new ArrayInput([]);
$cleanTempFilesCmd = $app->find('clean-temp-files');
$cleanTempFilesInput = new ArrayInput([]);
// Note if "subcommand" returns an exit code, run() method will return it.
$cleanRedisKeysCmd->run($cleanRedisKeysInput, $output);
$cleanTempFilesCmd->run($cleanTempFilesInput, $output);
}
Чтобы избежать дублирования кода, вы можете создать общий метод для вызова подкоманды. Что-то вроде этого:
private function executeSubCommand(string $name, array $parameters, OutputInterface $output)
{
return $this->getApplication()
->find($name)
->run(new ArrayInput($parameters), $output);
}