8000 Update bad entity name management · symfony/maker-bundle@749f523 · GitHub
[go: up one dir, main page]

Skip to content

Commit 749f523

Browse files
committed
Update bad entity name management
1 parent 07614b5 commit 749f523

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/Maker/MakeEntity.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
107107

108108
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
109109
{
110-
if ($input->getArgument('name')) {
111-
if (!$this->verifyEntityName($input->getArgument('name'))) {
112-
throw new \InvalidArgumentException('An entity can only have ASCII letters');
113-
}
114-
110+
if (($entityClassName = $input->getArgument('name')) && empty($this->verifyEntityName($entityClassName))) {
115111
return;
116112
}
117113

@@ -131,10 +127,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
131127

132128
$argument = $command->getDefinition()->getArgument('name');
133129
$question = $this->createEntityClassQuestion($argument->getDescription());
134-
$entityClassName = $io->askQuestion($question);
130+
$entityClassName ??= $io->askQuestion($question);
131+
132+
while ($dangerous = $this->verifyEntityName($entityClassName)) {
133+
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)) {
134+
break;
135+
}
135136

136-
while (!$this->verifyEntityName($entityClassName)) {
137-
$io->error('An entity can only have ASCII letters');
138137
$entityClassName = $io->askQuestion($question);
139138
}
140139

@@ -820,9 +819,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
820819
return $io->askQuestion($question);
821820
}
822821

823-
private function verifyEntityName(string $entityName): bool
822+
private function verifyEntityName(string $entityName): array
824823
{
825-
return preg_match('/^[a-zA-Z\\\\]+$/', $entityName);
824+
preg_match('/[^\x00-\x7F]/u', $entityName, $matches);
825+
826+
return $matches;
826827
}
827828

828829
private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator

tests/Maker/MakeEntityTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function getTestDetails(): \Generator
107107
$runner->runMaker([
108108
// entity class with accent
109109
'Usé',
110+
// Say no,
111+
'n',
110112
// entity class without accent
111113
'User',
112114
// no fields

tests/tmp/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)
0