Skip to content

Commit 77e6aed

Browse files
committed
Add documentation for extending IsGranted attribute
1 parent b83cfa0 commit 77e6aed

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

security.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,28 @@ that is thrown with the ``exceptionCode`` argument::
25232523
// ...
25242524
}
25252525

2526+
Extending ``IsGranted``
2527+
.......................
2528+
2529+
You can also extend the ``IsGranted`` class to create new attributes:
2530+
2531+
// src/Security/Attribute/IsAdmin.php
2532+
// ...
2533+
2534+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2535+
2536+
class IsAdmin extends IsGranted
2537+
{
2538+
public function __construct() {
2539+
return parent::__construct('ROLE_ADMIN');
2540+
}
2541+
}
2542+
2543+
.. versionadded:: 7.4
2544+
2545+
The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsGranted`
2546+
attribute is extendable since Symfony 7.4.
2547+
25262548
.. _security-template:
25272549

25282550
Access Control in Templates

0 commit comments

Comments
 (0)