@@ -2156,30 +2156,55 @@ will happen:
2156
2156
Thanks to the SensioFrameworkExtraBundle, you can also secure your controller
2157
2157
using annotations:
2158
2158
2159
- .. code -block :: diff
2159
+ .. configuration -block ::
2160
2160
2161
- // src/Controller/AdminController.php
2162
- // ...
2161
+ .. code-block :: php-annotations
2163
2162
2164
- + use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2163
+ // src/Controller/AdminController.php
2164
+ // ...
2165
2165
2166
- + /**
2167
- + * Require ROLE_ADMIN for *every* controller method in this class.
2168
- + *
2169
- + * @IsGranted("ROLE_ADMIN")
2170
- + */
2171
- class AdminController extends AbstractController
2172
- {
2173
- + /**
2174
- + * Require ROLE_ADMIN for only this controller method.
2175
- + *
2176
- + * @IsGranted("ROLE_ADMIN")
2177
- + */
2178
- public function adminDashboard(): Response
2179
- {
2180
- // ...
2181
- }
2182
- }
2166
+ use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2167
+
2168
+ /**
2169
+ * Require ROLE_ADMIN for all the actions of this controller
2170
+ *
2171
+ * @IsGranted("ROLE_ADMIN")
2172
+ */
2173
+ class AdminController extends AbstractController
2174
+ {
2175
+ /**
2176
+ * Require ROLE_SUPER_ADMIN only for this action
2177
+ *
2178
+ * @IsGranted("ROLE_SUPER_ADMIN")
2179
+ */
2180
+ public function adminDashboard(): Response
2181
+ {
2182
+ // ...
2183
+ }
2184
+ }
2185
+
2186
+ .. code-block :: php-attributes
2187
+
2188
+ // src/Controller/AdminController.php
2189
+ // ...
2190
+
2191
+ use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2192
+
2193
+ /**
2194
+ * Require ROLE_ADMIN for all the actions of this controller
2195
+ */
2196
+ #[IsGranted('ROLE_ADMIN')]
2197
+ class AdminController extends AbstractController
2198
+ {
2199
+ /**
2200
+ * Require ROLE_SUPER_ADMIN only for this action
2201
+ */
2202
+ #[IsGranted('ROLE_SUPER_ADMIN')]
2203
+ public function adminDashboard(): Response
2204
+ {
2205
+ // ...
2206
+ }
2207
+ }
2183
2208
2184
2209
For more information, see the `FrameworkExtraBundle documentation `_.
2185
2210
0 commit comments