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 3 commits
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 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 @@

$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 @@ -820,9 +819,11 @@
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);

return $matches;
}

private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator
Expand All @@ -835,7 +836,7 @@
$manipulator->setIo($io);

return $manipulator;
}

Check failure on line 839 in src/Maker/MakeEntity.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Symfony\Bundle\MakerBundle\Maker\MakeEntity::verifyEntityName() return type has no value type specified in iterable type array.

private function getPathOfClass(string $class): string
{
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