Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:entity] confirm to allow non-ascii char's in entity names #1496

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 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('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)) {
jrushlow marked this conversation as resolved.
Show resolved Hide resolved
break;
}

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

Expand Down Expand Up @@ -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
jrushlow marked this conversation as resolved.
Show resolved Hide resolved
{
return preg_match('/^[a-zA-Z\\\\]+$/', $entityName);
preg_match('/[^\x00-\x7F]/u', $entityName, $matches);
jrushlow marked this conversation as resolved.
Show resolved Hide resolved

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
Loading