entityManager = $entityManager; } protected function configure(): void { $this ->addArgument('name', InputArgument::OPTIONAL, 'Name of the group') ->addArgument('shortname', InputArgument::OPTIONAL, 'Shortname of the group') ; } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $helper = $this->getHelper('question'); $groupName = $input->getArgument('name'); if (!$groupName) { $questionName = new Question('Please enter the name of the group : ', ''); $questionName->setValidator(function ($answer) { if (!is_string($answer) || empty($answer)) { throw new \RuntimeException( 'The name c\'ant be empty' ); } return $answer; }); $groupName = $helper->ask($input, $output, $questionName); } $groupShortName = $input->getArgument('shortname'); if (!$groupShortName) { $questionShortName = new Question('Please enter the short name of the group : ', ''); $questionShortName->setValidator(function ($answer) { if (!is_string($answer) || empty($answer)) { throw new \RuntimeException( 'The shortname c\'ant be empty' ); } return $answer; }); $groupShortName = $helper->ask($input, $output, $questionShortName); } $Group = new Group(); $Group->setName($groupName); $Group->setShortName($groupShortName); $this->entityManager->persist($Group); try { $this->entityManager->flush(); $io->success('Group ' . $Group->getName() . ' created'); return Command::SUCCESS ; } catch (\Throwable $th) { $io->error('Error while creating ' . $Group->getName() . ' group'); return Command::FAILURE; } } }