diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 41f0287fb..88372a8a7 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('"%s" contains one or more non-ASCII characters, which are potentially problematic with some database. It is recommended to use only ASCII characters for entity names. Continue anyway?', $entityClassName), false)) { + break; + } - while (!$this->verifyEntityName($entityClassName)) { - $io->error('An entity can only have ASCII letters'); $entityClassName = $io->askQuestion($question); } @@ -820,9 +819,12 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $ return $io->askQuestion($question); } - private function verifyEntityName(string $entityName): bool + /** @return string[] */ + 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..31904c928 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