Skip to content

Commit 957aab4

Browse files
Fan2Shrekjrushlow
andauthored
bug #1496 [make:entity] confirm to allow non-ascii char's in entity names
Co-authored-by: Jesse Rushlow <[email protected]>
1 parent 6408fca commit 957aab4

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Maker/MakeEntity.php

Lines changed: 12 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('"%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)) {
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

@@ -837,9 +836,12 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
837836
return $io->askQuestion($question);
838837
}
839838

840-
private function verifyEntityName(string $entityName): bool
839+
/** @return string[] */
840+
private function verifyEntityName(string $entityName): array
841841
{
842-
return preg_match('/^[a-zA-Z\\\\]+$/', $entityName);
842+
preg_match('/([^\x00-\x7F]+)/u', $entityName, $matches);
843+
844+
return $matches;
843845
}
844846

845847
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

0 commit comments

Comments
 (0)