Explorar el Código

Mise à jour des commandes avec attributs

Sangfroid hace 8 meses
padre
commit
83fce1a49c

+ 6 - 6
src/Command/AppUserCreateCommand.php

@@ -10,23 +10,23 @@ use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Question\ChoiceQuestion;
 use Symfony\Component\Console\Question\Question;
 use App\Service\UserManager;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Style\SymfonyStyle;
 
+#[AsCommand(
+    name: 'app:user:create',
+    description: 'Créer un utilisateur',
+)]
 class AppUserCreateCommand extends Command
 {
-    private $userManager;
-
-    public function __construct(UserManager $userManager)
+    public function __construct(protected UserManager $userManager)
     {
-        $this->userManager = $userManager;
         parent::__construct();
     }
 
     protected function configure(): void
     {
         $this
-            ->setName('app:user:create')
-            ->setDescription('Créer un utilisateur')
             ->addArgument('argument', InputArgument::OPTIONAL, 'Argument description')
             ->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
         ;

+ 5 - 8
src/Command/AppUsersActivateCommand.php

@@ -4,12 +4,17 @@ namespace App\Command;
 
 use App\Repository\UserRepository;
 use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Question\ConfirmationQuestion;
 use Symfony\Component\Console\Style\SymfonyStyle;
 
+#[AsCommand(
+    name: 'app:users:activate',
+    description: 'Activer tous les users',
+)]
 class AppUsersActivateCommand extends Command
 {
     public function __construct(private UserRepository $repoUser, private EntityManagerInterface $em)
@@ -17,14 +22,6 @@ class AppUsersActivateCommand extends Command
         parent::__construct();
     }
 
-    protected function configure(): void
-    {
-        $this
-            ->setName('app:users:activate')
-            ->setDescription('Activer tous les users')
-        ;
-    }
-
     protected function execute(InputInterface $input, OutputInterface $output) :int
     {
         $io = new SymfonyStyle($input, $output);

+ 5 - 8
src/Command/UpdateCommentairesCommand.php

@@ -4,11 +4,16 @@ namespace App\Command;
 
 use App\Repository\FilmRepository;
 use App\Service\NoteMoyenne;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
 
+#[AsCommand(
+    name: 'app:commentaires:update',
+    description: 'Update les notes et nb coms',
+)]
 class UpdateCommentairesCommand extends Command
 {
 
@@ -17,14 +22,6 @@ class UpdateCommentairesCommand extends Command
         parent::__construct();
     }
 
-    protected function configure(): void
-    {
-        $this
-            ->setName('app:commentaires:update')
-            ->setDescription('Update les notes et nb coms')
-        ;
-    }
-
     protected function execute(InputInterface $input, OutputInterface $output) :int
     {
         $io = new SymfonyStyle($input, $output);

+ 5 - 2
src/Command/UpdateOptionsCommand.php

@@ -5,12 +5,17 @@ namespace App\Command;
 use App\Entity\Profile;
 use App\Repository\UserRepository;
 use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
 
+#[AsCommand(
+    name: 'app:update:options',
+    description: 'Commande pour rattacher une entité Profile aux users existants'
+)]
 class UpdateOptionsCommand extends Command
 {    
     public function __construct(private EntityManagerInterface $em, private UserRepository $repoUser)
@@ -21,8 +26,6 @@ class UpdateOptionsCommand extends Command
     protected function configure(): void
     {
         $this
-            ->setName('app:update:options')
-            ->setDescription('Commande pour rattacher une entité Profile aux users existants')
             ->addOption('force', null, InputOption::VALUE_NONE, 'Forcer la création des profils utilisateur')
         ;
     }