[DoctrineBridge] Auto-validation must work if no regex are passed
This commit is contained in:
parent
15f08553be
commit
5ed7d6c759
@ -173,7 +173,7 @@ class DoctrineLoaderTest extends TestCase
|
|||||||
public function regexpProvider()
|
public function regexpProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[false, null],
|
[true, null],
|
||||||
[true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'],
|
[true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'],
|
||||||
[false, '{^'.preg_quote(Entity::class).'$}'],
|
[false, '{^'.preg_quote(Entity::class).'$}'],
|
||||||
];
|
];
|
||||||
|
@ -43,7 +43,7 @@ final class DoctrineLoader implements LoaderInterface
|
|||||||
public function loadClassMetadata(ClassMetadata $metadata): bool
|
public function loadClassMetadata(ClassMetadata $metadata): bool
|
||||||
{
|
{
|
||||||
$className = $metadata->getClassName();
|
$className = $metadata->getClassName();
|
||||||
if (null === $this->classValidatorRegexp || !preg_match($this->classValidatorRegexp, $className)) {
|
if (null !== $this->classValidatorRegexp && !preg_match($this->classValidatorRegexp, $className)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@ class AddAutoMappingConfigurationPass implements CompilerPassInterface
|
|||||||
$validatorBuilder = $container->getDefinition($this->validatorBuilderService);
|
$validatorBuilder = $container->getDefinition($this->validatorBuilderService);
|
||||||
foreach ($container->findTaggedServiceIds($this->tag) as $id => $tags) {
|
foreach ($container->findTaggedServiceIds($this->tag) as $id => $tags) {
|
||||||
$regexp = $this->getRegexp(array_merge($globalNamespaces, $servicesToNamespaces[$id] ?? []));
|
$regexp = $this->getRegexp(array_merge($globalNamespaces, $servicesToNamespaces[$id] ?? []));
|
||||||
|
if (null === $regexp) {
|
||||||
|
$container->removeDefinition($id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp);
|
$container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp);
|
||||||
$validatorBuilder->addMethodCall('addLoader', [new Reference($id)]);
|
$validatorBuilder->addMethodCall('addLoader', [new Reference($id)]);
|
||||||
|
@ -81,6 +81,6 @@ class AddAutoMappingConfigurationPassTest extends TestCase
|
|||||||
|
|
||||||
(new AddAutoMappingConfigurationPass())->process($container);
|
(new AddAutoMappingConfigurationPass())->process($container);
|
||||||
|
|
||||||
$this->assertNull($container->getDefinition('loader')->getArgument('$classValidatorRegexp'));
|
$this->assertFalse($container->hasDefinition('loader'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user