Skip to content

Commit

Permalink
bug #1496 [make:entity] confirm to allow non-ascii char's in entity n…
Browse files Browse the repository at this point in the history
…ames

Co-authored-by: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com>
  • Loading branch information
Fan2Shrek and jrushlow authored May 19, 2024
1 parent 6408fca commit 957aab4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -837,9 +836,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
Expand Down
2 changes: 2 additions & 0 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 957aab4

Please sign in to comment.