Created
May 7, 2019 06:37
-
-
Save maciejmiara/8461b9b1871f6322d279bb88f24a2a17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
namespace Infrastructure\Framework\Command; | |
use Application\Command\EnrollRunnerToRun; | |
use Application\Handler\EnrollRunnerToRunHandler; | |
use Common\Id; | |
use Domain\Exception\DomainException; | |
use League\Tactician\CommandBus; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class RunnerParticipateCommand extends Command | |
{ | |
private $commandBus; | |
protected static $defaultName = 'runner:enroll'; | |
/** | |
* @param $commandBus | |
*/ | |
public function __construct(CommandBus $commandBus) | |
{ | |
$this->commandBus = $commandBus; | |
parent::__construct(); | |
} | |
protected function configure() | |
{ | |
$this->setDescription('Enroll runner to run'); | |
$this->addArgument('runnerId', InputArgument::REQUIRED, 'The id of runner'); | |
$this->addArgument('runId', InputArgument::REQUIRED, 'The id of run'); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$runnerId = Id::create($input->getArgument('runnerId')); | |
$runId = Id::create($input->getArgument('runId')); | |
$command = new EnrollRunnerToRun($runnerId, $runId); | |
try { | |
$this->commandBus->handle($command); | |
$output->writeln('Runner enrolled'); | |
} catch (DomainException $e) { | |
$output->writeln($e->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment