Skip to content

Commit

Permalink
Pass true to enableAnnotationMapping() (#7)
Browse files Browse the repository at this point in the history
* Pass true to enableAnnotationMapping()

* add setDoctrineAnnotationReader

* Move setupMapping to beforeCompile()

* default doctrine annotation reader if reader class not exists in DI

* fix phpstan

* bump symfony/validator dependency

Co-authored-by: Jiří Pudil <[email protected]>
  • Loading branch information
MartkCz and jiripudil authored Dec 30, 2021
1 parent 57fd909 commit b6ce363
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nette/di": "^3.0.1",
"symfony/cache": "^5.0",
"symfony/config": "^5.0",
"symfony/validator": "^5.0"
"symfony/validator": "^5.2"
},
"require-dev": {
"doctrine/annotations": "^1.8",
Expand Down
10 changes: 8 additions & 2 deletions src/DI/ValidatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function loadConfiguration(): void
->addSetup('setConstraintValidatorFactory', [new Statement(ContainerConstraintValidatorFactory::class)])
->setAutowired(false);

$this->setupMapping($validatorBuilder);
$this->setupCache($validatorBuilder);
$this->setupLoaders($validatorBuilder);
$this->setupObjectInitializers($validatorBuilder);
Expand All @@ -73,12 +72,19 @@ public function beforeCompile(): void
$validatorBuilder = $this->getContainerBuilder()->getDefinition($this->prefix('validatorBuilder'));
assert($validatorBuilder instanceof ServiceDefinition);
$this->setupTranslator($validatorBuilder);
$this->setupMapping($validatorBuilder);
}

private function setupMapping(ServiceDefinition $validatorBuilder): void
{
$validatorBuilder->addSetup('enableAnnotationMapping', [true]);

if ($this->config->mapping->annotations) {
$validatorBuilder->addSetup('enableAnnotationMapping');
if ((bool) $this->getContainerBuilder()->findByType(Reader::class)) {
$validatorBuilder->addSetup('setDoctrineAnnotationReader');
} else {
$validatorBuilder->addSetup('addDefaultDoctrineAnnotationReader');
}
}

$validatorBuilder->addSetup('addXmlMappings', [$this->config->mapping->xml]);
Expand Down

0 comments on commit b6ce363

Please sign in to comment.