How to use class constants in @Security annotation using the Symfony Expression Language?
You can use the constant()
function available in the Expression Language Component:
@Security("is_granted(constant('\\Full\\Namespace\\To\\OrgRoles::ROLE_ADMIN'), id)")
Doctrine annotation reader has made this even easier for constants in PHP code:
use MyCompany\Annotations\Bar;use MyCompany\Entity\SomeClass;/*** @Foo(PHP_EOL)* @Bar(Bar::FOO)*/
This also works just as expected for @Security / @IsGranted.
https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html#constants