Skip to content

Commit 0dacfd9

Browse files
committed
minor #21331 Add documentation for extending IsGranted attribute (tcoch)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- Add documentation for extending `IsGranted` attribute This PR adds documentation related to new feature symfony/symfony#61542 It will close issue #21326 Commits ------- eccf50a Add documentation for extending `IsGranted` attribute
2 parents b83cfa0 + eccf50a commit 0dacfd9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

security.rst

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

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

25282548
Access Control in Templates

0 commit comments

Comments
 (0)