Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Forked from maciejmiara/RunnerParticipate.php
Created March 11, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsh-code/e11bdad6900b86d436faa640f5da7262 to your computer and use it in GitHub Desktop.
Save tsh-code/e11bdad6900b86d436faa640f5da7262 to your computer and use it in GitHub Desktop.
Runner participation console command
<?php
namespace App\Console\Commands;
use Application\Command\EnrollRunnerToRun;
use Application\Handler\EnrollRunnerToRunHandler;
use Common\Id;
use Domain\Exception\DomainException;
use Illuminate\Console\Command;
use Joselfonseca\LaravelTactician\CommandBusInterface;
class RunnerParticipate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'runner:enroll {runnerId} {runId}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enroll runner to run';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(CommandBusInterface $commandBus)
{
$commandBus->addHandler(EnrollRunnerToRun::class, EnrollRunnerToRunHandler::class);
$runnerId = Id::create($this->argument('runnerId'));
$runId = Id::create($this->argument('runId'));
$command = new EnrollRunnerToRun($runnerId, $runId);
try {
$commandBus->dispatch($command);
$this->info('Runner enrolled');
} catch (DomainException $e) {
$this->error($e->getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment