Symfony compile annotated classes

553 Views Asked by At

I'm interested in Symfony\Component\HttpKernel\DependencyInjection\Extension::getAnnotatedClassesToCompile() method. If I understand it correctly, you can addAnnotatedClassesToCompile() an array of classes (which uses annotations) namespaces. Then during cache warmup all these classes annotations become warmed up. Am I right or something is missing?

If its correct, then why symfony adds Symfony\Bundle\FrameworkBundle\Controller\AbstractController, Symfony\Bundle\FrameworkBundle\Controller\Controller to annotated classes? I cant find any annotations in it...

1

There are 1 best solutions below

0
On BEST ANSWER

https://symfony.com/doc/current/bundles/extension.html#adding-classes-to-compile

If some class extends from other classes, all its parents are automatically included in the list of classes to compile.

As your controllers will extend Controller or AbstractController that means these will always be checked for annotations so it makes sense to cache the fact they have none. Adding them to addAnnotatedClassesToCompile ensures this is done even if you didn't dump an optimized autoloader.