diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 41f0287fb..a6e33a768 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -107,11 +107,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void { - if ($input->getArgument('name')) { - if (!$this->verifyEntityName($input->getArgument('name'))) { - throw new \InvalidArgumentException('An entity can only have ASCII letters'); - } - + if (($entityClassName = $input->getArgument('name')) && empty($this->verifyEntityName($entityClassName))) { return; } @@ -131,10 +127,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $argument = $command->getDefinition()->getArgument('name'); $question = $this->createEntityClassQuestion($argument->getDescription()); - $entityClassName = $io->askQuestion($question); + $entityClassName ??= $io->askQuestion($question); + + while ($dangerous = $this->verifyEntityName($entityClassName)) { + if ($io->confirm(sprintf('The %s character is non-ASCII, which are potentially problematic with some database. It is recommended to use only ASCII characters in entity names. Would you keep entered name ?', $dangerous[0]), false)) { + break; + } - while (!$this->verifyEntityName($entityClassName)) { - $io->error('An entity can only have ASCII letters'); $entityClassName = $io->askQuestion($question); } @@ -820,9 +819,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $ return $io->askQuestion($question); } - private function verifyEntityName(string $entityName): bool + private function verifyEntityName(string $entityName): array { - return preg_match('/^[a-zA-Z\\\\]+$/', $entityName); + preg_match('/[^\x00-\x7F]/u', $entityName, $matches); + + return $matches; } private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index 2b5605b39..69254d338 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -107,6 +107,8 @@ public function getTestDetails(): \Generator $runner->runMaker([ // entity class with accent 'Usé', + // Say no, + 'n', // entity class without accent 'User', // no fields