OrmExtension
aleswita opened this issue · comments
Aleš commented
You are using current version of dev-master in our project?
On my project extension still throws this exception "AnnotationReader missing in DIC, please use Nettrine/Annotations or implement own MetadataProvider."
It's because, that getByType method returning still null, because anotation extension set anotation reader as autowired = false.
Look at the docs: https://api.nette.org/2.4/source-DI.ContainerBuilder.php.html#225
I think this is correct:
if (count($builder->findByType(AnnotationReader::class)) === 0) {
throw new \Exception('AnnotationReader missing in DIC, please use Nettrine/Annotations or implement own MetadataProvider.');
}
Aleš commented
..or what you think about this:
$reader = $builder->getByType(AnnotationReader::class);
if ($reader === null) {
$readers = $builder->findByType(AnnotationReader::class);
if (count($readers) === 0) {
throw new \Exception('AnnotationReader missing in DIC, please use Nettrine/Annotations or implement own MetadataProvider.');
} elseif (count($readers) > 1) {
throw new \Exception('Multiple services of type "Doctrine\\Common\\Annotations\\AnnotationReader".');
}
$reader = end($readers);
}
$annotationDriver = $builder->addDefinition($this->prefix('annotationDriver'))
->setType(AnnotationDriver::class)
->setArguments([$reader, $builder->expand('%appDir%')]);
$configuration->addSetup('setMetadataDriverImpl', [$annotationDriver]);
Milan Felix Šulc commented
What about change autowired to TRUE
? It would solve this problem. :-)
Aleš commented
👍
I will send PR.