contributte / doctrine-orm

:fire: Well-integrated Doctrine ORM for Nette Framework

Home Page:https://contributte.org/packages/nettrine/orm.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OrmExtension

aleswita opened this issue · comments

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.');
}
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]);

What about change autowired to TRUE? It would solve this problem. :-)

commented

👍

I will send PR.