From eccf50a78a0767795c6ace823099c2ee17d87512 Mon Sep 17 00:00:00 2001 From: tcoch Date: Fri, 29 Aug 2025 22:40:30 +0200 Subject: [PATCH] Add documentation for extending `IsGranted` attribute --- security.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/security.rst b/security.rst index 8218b4ec355..6187c8c3bbe 100644 --- a/security.rst +++ b/security.rst @@ -2523,6 +2523,26 @@ that is thrown with the ``exceptionCode`` argument:: // ... } +You can also extend the ``IsGranted`` attribute to create meaningful shortcuts:: + + // src/Security/Attribute/IsAdmin.php + // ... + + use Symfony\Component\Security\Http\Attribute\IsGranted; + + class IsAdmin extends IsGranted + { + public function __construct() + { + return parent::__construct('ROLE_ADMIN'); + } + } + +.. versionadded:: 7.4 + + The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsGranted` + attribute is extendable since Symfony 7.4. + .. _security-template: Access Control in Templates