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

This commit is contained in:
Kévin Dunglas 2019-10-03 11:47:46 +02:00
parent 15f08553be
commit 5ed7d6c759
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
4 changed files with 7 additions and 3 deletions

View File

@ -173,7 +173,7 @@ class DoctrineLoaderTest extends TestCase
public function regexpProvider()
{
return [
[false, null],
[true, null],
[true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'],
[false, '{^'.preg_quote(Entity::class).'$}'],
];

View File

@ -43,7 +43,7 @@ final class DoctrineLoader implements LoaderInterface
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;
}

View File

@ -59,6 +59,10 @@ class AddAutoMappingConfigurationPass implements CompilerPassInterface
$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)]);

View File

@ -81,6 +81,6 @@ class AddAutoMappingConfigurationPassTest extends TestCase
(new AddAutoMappingConfigurationPass())->process($container);
$this->assertNull($container->getDefinition('loader')->getArgument('$classValidatorRegexp'));
$this->assertFalse($container->hasDefinition('loader'));
}
}