TaskerBridges/src/Symfony/SymfonyCommandAdapter.php

45 lines
1.5 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Phred\TaskerBridges\Symfony;
use Phred\ConsoleContracts\CommandInterface;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface as SymfonyInputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface as SymfonyOutputInterface;
/**
* Adapter to run Phred commands within a Symfony Console application.
*/
class SymfonyCommandAdapter extends SymfonyCommand
{
public function __construct(private readonly CommandInterface $phredCommand)
{
parent::__construct($phredCommand->getName());
}
protected function configure(): void
{
$this->setDescription($this->phredCommand->getDescription());
foreach ($this->phredCommand->getArguments() as $name => $description) {
$this->addArgument($name, InputArgument::OPTIONAL, $description);
}
foreach ($this->phredCommand->getOptions() as $name => $description) {
$this->addOption($name, null, InputOption::VALUE_OPTIONAL, $description);
}
}
protected function execute(SymfonyInputInterface $input, SymfonyOutputInterface $output): int
{
$phredInput = new SymfonyInputAdapter($input);
$phredOutput = new SymfonyOutputAdapter($output);
return $this->phredCommand->execute($phredInput, $phredOutput);
}
}