8000 [DoctrineBridge] Auto-validation must work if no regex are passed by dunglas · Pull Request #33828 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Auto-validation must work if no regex are passed #33828

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

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
[DoctrineBridge] Auto-validation must work if no regex are passed
  • Loading branch information
dunglas committed Oct 29, 2019
commit 5ed7d6c759c63e512532fcc4a37019f3b7dd12c4
< 8000 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp
public function regexpProvider()
{
return [
[false, null],
[true, null],
[true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'],
[false, '{^'.preg_quote(Entity::class).'$}'],
];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(EntityManagerInterface $entityManager, string $class
public function loadClassMetadata(ClassMetadata $metadata): bool
{
$className = $metadata->getClassName();
if (null === $this->classValidatorRegexp || !preg_match($this->classValidatorRegexp, $className)) {
if (null !== $this->classValidatorRegexp && !preg_match($this->classValidatorRegexp, $className)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function process(ContainerBuilder $container)
$validatorBuilder = $container->getDefinition($this->validatorBuilderService);
foreach ($container->findTaggedServiceIds($this->tag) as $id => $tags) {
$regexp = $this->getRegexp(array_merge($globalNamespaces, $servicesToNamespaces[$id] ?? []));
if (null === $regexp) {
$container->removeDefinition($id);
continue;
}

$container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp);
$validatorBuilder->addMethodCall('addLoader', [new Reference($id)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public function testDoNotMapAllClassesWhenConfigIsEmpty()

(new AddAutoMappingConfigurationPass())->process($container);

$this->assertNull($container->getDefinition('loader')->getArgument('$classValidatorRegexp'));
$this->assertFalse($container->hasDefinition('loader'));
}
}
0