From 55c7189e20384d1a14361ef951384563d5d077d3 Mon Sep 17 00:00:00 2001 From: Fan2Shrek Date: Sat, 30 Mar 2024 21:54:30 +0100 Subject: [PATCH 1/4] Update bad entity name management --- src/Maker/MakeEntity.php | 21 +++++++++++---------- tests/Maker/MakeEntityTest.php | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) 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..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 From 0aff05968271797afcda3b2d5d35ff1f6f9f02a2 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Sun, 19 May 2024 00:41:12 -0400 Subject: [PATCH 2/4] regex to capture all hits as one group --- src/Maker/MakeEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index a6e33a768..a1c100f73 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -821,7 +821,7 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $ private function verifyEntityName(string $entityName): array { - preg_match('/[^\x00-\x7F]/u', $entityName, $matches); + preg_match('/([^\x00-\x7F]+)/u', $entityName, $matches); return $matches; } From aba323736255d84e7163f21c4b600e12e3ec7796 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Sun, 19 May 2024 00:41:31 -0400 Subject: [PATCH 3/4] one time ask --- src/Maker/MakeEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index a1c100f73..dda9cb9e3 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -130,7 +130,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $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)) { + 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; } From 08030edecd4dbea78607b2d5220e910e5b333c59 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Sun, 19 May 2024 00:47:45 -0400 Subject: [PATCH 4/4] show array shape --- src/Maker/MakeEntity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index dda9cb9e3..88372a8a7 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -819,6 +819,7 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $ return $io->askQuestion($question); } + /** @return string[] */ private function verifyEntityName(string $entityName): array { preg_match('/([^\x00-\x7F]+)/u', $entityName, $matches);