55namespace App \Command \User ;
66
77use App \Message \User \CreateUser ;
8+ use Symfony \Component \Console \Attribute \Argument ;
89use Symfony \Component \Console \Attribute \AsCommand ;
910use Symfony \Component \Console \Command \Command ;
10- use Symfony \Component \Console \Input \InputArgument ;
11- use Symfony \Component \Console \Input \InputInterface ;
12- use Symfony \Component \Console \Output \OutputInterface ;
1311use Symfony \Component \Console \Style \SymfonyStyle ;
1412use Symfony \Component \Messenger \MessageBusInterface ;
1513use Symfony \Component \Validator \Validator \ValidatorInterface ;
1816class CreateCommand extends Command
1917{
2018 public function __construct (
21- private MessageBusInterface $ messageBus ,
19+ private readonly MessageBusInterface $ messageBus ,
2220 private readonly ValidatorInterface $ validator ,
2321 ) {
2422 parent ::__construct ();
2523 }
2624
27- protected function execute (InputInterface $ input , OutputInterface $ output ): int
28- {
29- $ io = new SymfonyStyle ($ input , $ output );
30-
25+ public function __invoke (
26+ SymfonyStyle $ io ,
27+ #[Argument(description: 'The email of the user ' )] string $ email ,
28+ #[Argument(description: 'The roles of the user ' )] array $ roles = ['ROLE_USER ' ],
29+ ): int {
3130 $ message = new CreateUser ();
32- $ message ->email = $ input -> getArgument ( ' email ' ) ;
33- $ message ->roles = $ input -> getArgument ( ' roles ' ) ;
31+ $ message ->email = $ email ;
32+ $ message ->roles = $ roles ;
3433
3534 $ constraints = $ this ->validator ->validate ($ message );
3635 if ($ constraints ->count () > 0 ) {
@@ -47,19 +46,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4746
4847 return Command::SUCCESS ;
4948 }
50-
51- protected function configure (): void
52- {
53- $ this ->addArgument (
54- 'email ' ,
55- InputArgument::REQUIRED ,
56- 'The email of the user '
57- );
58- $ this ->addArgument (
59- 'roles ' ,
60- InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
61- 'The roles of the user ' ,
62- ['ROLE_USER ' ]
63- );
64- }
6549}
0 commit comments