@@ -2199,30 +2199,55 @@ will happen:
2199
2199
Thanks to the SensioFrameworkExtraBundle, you can also secure your controller
2200
2200
using annotations:
2201
2201
2202
- .. code -block :: diff
2202
+ .. configuration -block ::
2203
2203
2204
- // src/Controller/AdminController.php
2205
- // ...
2204
+ .. code-block :: php-annotations
2206
2205
2207
- + use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2206
+ // src/Controller/AdminController.php
2207
+ // ...
2208
2208
2209
- + /**
2210
- + * Require ROLE_ADMIN for *every* controller method in this class.
2211
- + *
2212
- + * @IsGranted("ROLE_ADMIN")
2213
- + */
2214
- class AdminController extends AbstractController
2215
- {
2216
- + /**
2217
- + * Require ROLE_ADMIN for only this controller method.
2218
- + *
2219
- + * @IsGranted("ROLE_ADMIN")
2220
- + */
2221
- public function adminDashboard(): Response
2222
- {
2223
- // ...
2224
- }
2225
- }
2209
+ use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2210
+
2211
+ /**
2212
+ * Require ROLE_ADMIN for all the actions of this controller
2213
+ *
2214
+ * @IsGranted("ROLE_ADMIN")
2215
+ */
2216
+ class AdminController extends AbstractController
2217
+ {
2218
+ /**
2219
+ * Require ROLE_SUPER_ADMIN only for this action
2220
+ *
2221
+ * @IsGranted("ROLE_SUPER_ADMIN")
2222
+ */
2223
+ public function adminDashboard(): Response
2224
+ {
2225
+ // ...
2226
+ }
2227
+ }
2228
+
2229
+ .. code-block :: php-attributes
2230
+
2231
+ // src/Controller/AdminController.php
2232
+ // ...
2233
+
2234
+ use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2235
+
2236
+ /**
2237
+ * Require ROLE_ADMIN for all the actions of this controller
2238
+ */
2239
+ #[IsGranted('ROLE_ADMIN')]
2240
+ class AdminController extends AbstractController
2241
+ {
2242
+ /**
2243
+ * Require ROLE_SUPER_ADMIN only for this action
2244
+ */
2245
+ #[IsGranted('ROLE_SUPER_ADMIN')]
2246
+ public function adminDashboard(): Response
2247
+ {
2248
+ // ...
2249
+ }
2250
+ }
2226
2251
2227
2252
For more information, see the `FrameworkExtraBundle documentation `_.
2228
2253
0 commit comments