Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active December 25, 2022 20:06
Show Gist options
  • Save ismail1432/5e25f71b9c566d1ae9b202e25d67600b to your computer and use it in GitHub Desktop.
Save ismail1432/5e25f71b9c566d1ae9b202e25d67600b to your computer and use it in GitHub Desktop.
<?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