do not enable validator auto mapping by default
This commit is contained in:
parent
9c76aae7dd
commit
a3555fc49c
@ -36,7 +36,7 @@ class DoctrineLoaderTest extends TestCase
|
||||
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->enableAnnotationMapping()
|
||||
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager()))
|
||||
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoaderEntity$}'))
|
||||
->getValidator()
|
||||
;
|
||||
|
||||
@ -111,7 +111,7 @@ class DoctrineLoaderTest extends TestCase
|
||||
public function regexpProvider()
|
||||
{
|
||||
return [
|
||||
[true, null],
|
||||
[false, null],
|
||||
[true, '{^'.preg_quote(DoctrineLoaderEntity::class).'$|^'.preg_quote(Entity::class).'$}'],
|
||||
[false, '{^'.preg_quote(Entity::class).'$}'],
|
||||
];
|
||||
|
@ -42,7 +42,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;
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,12 @@ class AddAutoMappingConfigurationPass implements CompilerPassInterface
|
||||
/**
|
||||
* Builds a regexp to check if a class is auto-mapped.
|
||||
*/
|
||||
private function getRegexp(array $patterns): string
|
||||
private function getRegexp(array $patterns): ?string
|
||||
{
|
||||
if (!$patterns) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$regexps = [];
|
||||
foreach ($patterns as $pattern) {
|
||||
// Escape namespace
|
||||
|
@ -70,4 +70,17 @@ class AddAutoMappingConfigurationPassTest extends TestCase
|
||||
['Symfony\Component\Validator\Tests\Fixtures\\**', ['trailing_double_star'], '{^App\\\\|^Symfony\\\\Component\\\\Validator\\\\Tests\\\\Fixtures\\\\.*?$}'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testDoNotMapAllClassesWhenConfigIsEmpty()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('validator.auto_mapping', []);
|
||||
|
||||
$container->register('validator.builder', ValidatorBuilder::class);
|
||||
$container->register('loader')->addTag('validator.auto_mapper');
|
||||
|
||||
(new AddAutoMappingConfigurationPass())->process($container);
|
||||
|
||||
$this->assertNull($container->getDefinition('loader')->getArgument('$classValidatorRegexp'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user