This Twig extension allows to access public static attributes and methods of a class.
- Copy the file Reflection.php in the Twig/Extension directory of your Bundle/Module.
- Declare the extension. For example in Symfony 2/3, you have to do it in the app/config/services.yml :
site.twig.reflectionExtension:
class: AppBundle\Twig\Extension\Reflection
tags:
- { name: twig.extension }
There are two methods callable in this extension :
* callStaticMethod($className, $methodName, array $args = [])
* getStaticAttribute($className, $attributeName)
From your Twig template, just call the good one with the proper parameters, for example:
set arrType = getStaticAttribute('AppBundle\\Entity\\Book', 'arrSearchTypes')