1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Command;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- 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
- {
- public function __construct(protected UserManager $userManager)
- {
- parent::__construct();
- }
- protected function configure(): void
- {
- $this
- ->addArgument('argument', InputArgument::OPTIONAL, 'Argument description')
- ->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
- ;
- }
- protected function execute(InputInterface $input, OutputInterface $output) : int
- {
- $io = new SymfonyStyle($input, $output);
- $username = $io->askQuestion(new Question('Nom (username) de l\'utilisateur '));
- $prenom = $io->askQuestion(new Question('Prénom de l\'utilisateur '));
- $nom = $io->askQuestion(new Question('Nom de l\'utilisateur '));
- $mail = $io->askQuestion(new Question('Email ', 'bidule@truc.chose'));
- $password = $io->askHidden("Mot de passe");
- $roles = $io->askQuestion((new ChoiceQuestion('Roles ', array('ROLE_SUPER_ADMIN', 'ROLE_ADMIN', 'ROLE_USER', 'ROLE_MODERATEUR'), '0'))->setMultiselect(true));
- $this->userManager->createUser(
- "$username",
- "$password",
- "$nom",
- "$prenom",
- "$mail",
- $roles,
- true);
- $io->success('Nom du pélo : '.$username);
- return COMMAND::SUCCESS;
- }
- }
|