JMSDiExtraBundle
JMSDiExtraBundle copied to clipboard
Vendor classes loaded but they shouldn't
Hi,
not sure if this is a bug or a configuration problem on my side.
When using SonataUserBundle and JMSDiExtraBundle, Sonata's code triggers an annotation exception (because of a missing optional dependency only needed if the api controllers are used).
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\UserController::getUsersAction() does not exist, or could not be auto-loaded.
The routing for those api controllers is added optionally by SonataUserBundle, depending on if some other bundles are available. But SonataUserBundle is definitely not loading the api controllers by itself in this case.
Somehow JMSDiExtraBundle seems to cause their api controllers to load, despite I have configured:
jms_di_extra:
locations:
all_bundles: false
Is there anything else to configure so that DiExtraBundle does not cause loading other vendor classes?
I have set up a minimal project here for demonstrating the issue.
This happening here:
- https://github.com/schmittjoh/JMSDiExtraBundle/blob/master/HttpKernel/ControllerInjectorsWarmer.php#L35
Cache warmer try to find all controllers in all bundles. After this it create injector for every controller class, including controllers with @Nelmio\ApiDocBundle\Annotation\ApiDoc annotation.
Good spot @covex-nn ! Thank you.
So there is at least a possible workaround by adding the affected controllers to
jms_di_extra.cache_warmer.controller_file_blacklist
I think i have found a problem. And it is not possible to ignore @ApiDoc annotation right now: doctrine/annotations package does not allow to ignore valid annotations =(
Also i have found PR in doctrine/annotations repo: DocParser can now ignore whole namespaces. But in that PR @BreiteSeite tried to ignore non-valid annotations. So, it will not help to solve this problem yet.