Last active
December 25, 2022 20:06
-
-
Save ismail1432/5e25f71b9c566d1ae9b202e25d67600b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
namespace App\Application\Command; | |
use App\Domain\CreateAUserHandler; | |
use App\Domain\CreateAUserInput; | |
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 CreateUserCommand extends Command | |
{ | |
protected static $defaultName = 'create-user'; | |
private CreateAUserHandler $handler | |
public function __construct(CreateAUserHandler $handler) | |
{ | |
parent::__construct(self::$defaultName); | |
$this->handler = $handler; | |
} | |
protected function configure(): void | |
{ | |
$this | |
->addArgument('name', InputArgument::REQUIRED, 'the name of the user to create') | |
->addArgument('age', InputArgument::REQUIRED, 'the age of the user to create') | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | |
$name = $input->getArgument('name'); | |
$age = $input->getArgument('age'); | |
$this->handler->execute(new CreateAUserInput( | |
$name, | |
$age | |
)); | |
return Command::SUCCESS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment