doctrine / DoctrineCouchDBBundle

Symfony Bundle for DoctrineCouchDB
http://www.doctrine-project.org
Other
49 stars 46 forks source link

Docs recommend using deprecated functions for Annotations #60

Open silverbackdan opened 6 years ago

silverbackdan commented 6 years ago

The Readme suggests adding this to load the annotations:

use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

I went to do this and saw that it is deprecated and will be removed in 2.0

I don't like using deprecated functions and without calling that I get an error

[Semantical Error] The annotation "@Doctrine\ODM\CouchDB\Mapping\Annotations\Document" in class App\CouchDocument\Product does not exist, or could not be auto-loaded. 

I've noticed within the bundle there are a couple of calls to deprecated functions too such as in TestInit.php

Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace

I don't suppose there's a quick solution to this? I've read that doctrine should use the autoload.php file but it doesn't seem to be for me I don't think.

silverbackdan commented 6 years ago

Weirdly, if I change the annotations between use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB; and use Doctrine\ODM\CouchDB\Mapping\Annotations\Id for example, the first load runs without an error.

silverbackdan commented 6 years ago

OK, I understand what is going on now. SF4 has a config file in their framework that runs only on the first load: https://github.com/symfony/symfony/blob/0b1b8959d371d4baf9db9db6f537e59d686f89c2/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml#L18-L22

I've raised an issue about this. I feel it should run every time or not at all. Therefore it'd add the loader class_exists

I remember seeing this while trawling through code though: https://github.com/doctrine/annotations/blob/master/lib/Doctrine/Common/Annotations/AnnotationRegistry.php#L136

Perhaps a simple solution to not require the deprecated function calls could be to change the 'autoload' flag to true (back to default) - I'm not sure but it may solve the issue.

silverbackdan commented 5 years ago

Update: this was not a SF4 issue. Annotations loader just needs updating in this bundle at some point. I'm not actively using the bundle right now so probably won't be able to write a PR but I'll leave the issue open just in case.