Skip to content

Commit de2fc32

Browse files
committed
Tweaks
1 parent 8e2b228 commit de2fc32

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

security/expressions.rst

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ and ``#[IsGranted()]`` attribute also accept an
2626
2727
class MyController extends AbstractController
2828
{
29+
#[IsGranted(new Expression('is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'))]
30+
public function show(): Response
31+
{
32+
// ...
33+
}
34+
2935
#[IsGranted(new Expression(
3036
'"ROLE_ADMIN" in role_names or (is_authenticated() and user.isSuperAdmin())'
3137
))]
32-
public function index(): Response
38+
public function edit(): Response
3339
{
3440
// ...
3541
}
3642
}
37-
.. code-block:: php-attributes
43+
44+
.. code-block:: php
3845
3946
// src/Controller/MyController.php
4047
namespace App\Controller;
@@ -45,25 +52,16 @@ and ``#[IsGranted()]`` attribute also accept an
4552
4653
class MyController extends AbstractController
4754
{
48-
#[IsGranted(new Expression('is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'))]
49-
public function index(): Response
55+
public function show(): Response
5056
{
57+
$this->denyAccessUnlessGranted(new Expression(
58+
'is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'
59+
));
60+
5161
// ...
5262
}
53-
}
54-
55-
.. code-block:: php
56-
57-
// src/Controller/MyController.php
58-
namespace App\Controller;
5963
60-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
61-
use Symfony\Component\ExpressionLanguage\Expression;
62-
use Symfony\Component\HttpFoundation\Response;
63-
64-
class MyController extends AbstractController
65-
{
66-
public function index(): Response
64+
public function edit(): Response
6765
{
6866
$this->denyAccessUnlessGranted(new Expression(
6967
'"ROLE_ADMIN" in role_names or (is_authenticated() and user.isSuperAdmin())'

0 commit comments

Comments
 (0)