Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AnnotationException in AbstractController #32347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mike-henders opened this issue Jul 3, 2019 · 2 comments
Closed

AnnotationException in AbstractController #32347

mike-henders opened this issue Jul 3, 2019 · 2 comments

Comments

@mike-henders
Copy link

mike-henders commented Jul 3, 2019

In Symfony 4.2.8, extending AbstractController generates an AnnotationException with the following error message:
Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation @required in method Symfony\Bundle\FrameworkBundle\Controller\AbstractController::setContainer() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /home/ubuntu/public_html/mikehhero/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54

We are using SensioFrameworkExtra bundle with @Route, @Security and @IsGranted annotations without problems. This was our first attempt to use the AbstractController and autowiring instead of the deprecated Controller.

I assume it is a misconfiguration but I'm not sure where to look to resolve it.

@derrabus
Copy link
Member

derrabus commented Jul 3, 2019

Can you create a small application to reproduce the problem?

@mike-henders
Copy link
Author

The problem did not reproduce in a small application which is why I was pretty sure it was a misconfiguration. After a few hours of debugging I diagnosed and solved the problem. I'll post the answer here for other people who run into the issue.

This project in question is long-lived and at one point used Symfony 2. Consequently we had defined our own annotations.reader service in the services.yml file:

# config/services.yml
services:
    annotations.reader:
        class: Doctrine\Common\Annotations\AnnotationReader
        public: false

This was overriding the service definition provided by symfony/framework-bundle in the annotations.xml file:

  <!-- vendor/symfony/framework-bundle/Resources/config/annotations.xml -->
  <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader">
        <call method="addGlobalIgnoredName">
            <argument>required</argument>
            <!-- dummy arg to register class_exists as annotation loader only when required -->
            <argument type="service" id="annotations.dummy_registry" />
        </call>
    </service>

Since the overridden service didn't add the required keyword the DocParser thew an AnnotationException due to a semanticalError when it encountered the @required annotation in the AbstractController::setContainer method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants