File tree Expand file tree Collapse file tree 3 files changed +16
-12
lines changed
Expand file tree Collapse file tree 3 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1515use App \Repository \UserRepository ;
1616use App \Utils \Validator ;
1717use Doctrine \ORM \EntityManagerInterface ;
18+ use Symfony \Component \Console \Attribute \AsCommand ;
1819use Symfony \Component \Console \Command \Command ;
1920use Symfony \Component \Console \Exception \RuntimeException ;
2021use Symfony \Component \Console \Input \InputArgument ;
4647 * @author Javier Eguiluz <javier.eguiluz@gmail.com>
4748 * @author Yonel Ceruto <yonelceruto@gmail.com>
4849 */
50+ #[AsCommand(
51+ name: 'app:add-user ' ,
52+ description: 'Creates users and stores them in the database '
53+ )]
4954class AddUserCommand extends Command
5055{
51- // to make your command lazily loaded, configure the $defaultName static property,
52- // so it will be instantiated only when the command is actually called.
53- protected static $ defaultName = 'app:add-user ' ;
54-
5556 private SymfonyStyle $ io ;
5657
5758 public function __construct (
@@ -69,7 +70,6 @@ public function __construct(
6970 protected function configure (): void
7071 {
7172 $ this
72- ->setDescription ('Creates users and stores them in the database ' )
7373 ->setHelp ($ this ->getCommandHelp ())
7474 // commands can optionally define arguments and/or options (mandatory and optional)
7575 // see https://symfony.com/doc/current/components/console/console_arguments.html
Original file line number Diff line number Diff line change 1515use App \Repository \UserRepository ;
1616use App \Utils \Validator ;
1717use Doctrine \ORM \EntityManagerInterface ;
18+ use Symfony \Component \Console \Attribute \AsCommand ;
1819use Symfony \Component \Console \Command \Command ;
1920use Symfony \Component \Console \Exception \RuntimeException ;
2021use Symfony \Component \Console \Input \InputArgument ;
3738 *
3839 * @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
3940 */
41+ #[AsCommand(
42+ name: 'app:delete-user ' ,
43+ description: 'Deletes users from the database '
44+ )]
4045class DeleteUserCommand extends Command
4146{
42- protected static $ defaultName = 'app:delete-user ' ;
43-
4447 private SymfonyStyle $ io ;
4548
4649 public function __construct (
@@ -57,7 +60,6 @@ public function __construct(
5760 protected function configure (): void
5861 {
5962 $ this
60- ->setDescription ('Deletes users from the database ' )
6163 ->addArgument ('username ' , InputArgument::REQUIRED , 'The username of an existing user ' )
6264 ->setHelp (<<<'HELP'
6365The <info>%command.name%</info> command deletes users from the database:
Original file line number Diff line number Diff line change 1313
1414use App \Entity \User ;
1515use App \Repository \UserRepository ;
16+ use Symfony \Component \Console \Attribute \AsCommand ;
1617use Symfony \Component \Console \Command \Command ;
1718use Symfony \Component \Console \Input \InputInterface ;
1819use Symfony \Component \Console \Input \InputOption ;
3738 *
3839 * @author Javier Eguiluz <javier.eguiluz@gmail.com>
3940 */
41+ #[AsCommand(
42+ name: 'app:list-users ' ,
43+ description: 'Lists all the existing users ' ,
44+ aliases: ['app:users ' ]
45+ )]
4046class ListUsersCommand extends Command
4147{
42- // a good practice is to use the 'app:' prefix to group all your custom application commands
43- protected static $ defaultName = 'app:list-users ' ;
44-
4548 public function __construct (
4649 private MailerInterface $ mailer ,
4750 private string $ emailSender ,
@@ -56,7 +59,6 @@ public function __construct(
5659 protected function configure (): void
5760 {
5861 $ this
59- ->setDescription ('Lists all the existing users ' )
6062 ->setHelp (<<<'HELP'
6163The <info>%command.name%</info> command lists all the users registered in the application:
6264
You can’t perform that action at this time.
0 commit comments