@@ -130,9 +130,7 @@ Using Expressions for Complex Security Restrictions
130
130
If your security logic is a little bit more complex, you can use an :doc: `expression </components/expression_language >`
131
131
inside ``@Security ``. In the following example, a user can only access the
132
132
controller if their email matches the value returned by the ``getAuthorEmail() ``
133
- method on the ``Post `` object:
134
-
135
- .. code-block :: php
133
+ method on the ``Post `` object::
136
134
137
135
use AppBundle\Entity\Post;
138
136
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -163,9 +161,7 @@ need to repeat the expression code using Twig syntax:
163
161
{% endif %}
164
162
165
163
The easiest solution - if your logic is simple enough - is to add a new method
166
- to the ``Post `` entity that checks if a given user is its author:
167
-
168
- .. code-block :: php
164
+ to the ``Post `` entity that checks if a given user is its author::
169
165
170
166
// src/AppBundle/Entity/Post.php
171
167
// ...
@@ -185,9 +181,7 @@ to the ``Post`` entity that checks if a given user is its author:
185
181
}
186
182
}
187
183
188
- Now you can reuse this method both in the template and in the security expression:
189
-
190
- .. code-block :: php
184
+ Now you can reuse this method both in the template and in the security expression::
191
185
192
186
use AppBundle\Entity\Post;
193
187
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -217,9 +211,7 @@ Checking Permissions without @Security
217
211
The above example with ``@Security `` only works because we're using the
218
212
:ref: `ParamConverter <best-practices-paramconverter >`, which gives the expression
219
213
access to the ``post `` variable. If you don't use this, or have some other
220
- more advanced use-case, you can always do the same security check in PHP:
221
-
222
- .. code-block :: php
214
+ more advanced use-case, you can always do the same security check in PHP::
223
215
224
216
/**
225
217
* @Route("/{id}/edit", name="admin_post_edit")
@@ -257,9 +249,7 @@ of magnitude easier than :doc:`ACLs </security/acl>` and will give
257
249
you the flexibility you need in almost all cases.
258
250
259
251
First, create a voter class. The following example shows a voter that implements
260
- the same ``getAuthorEmail() `` logic you used above:
261
-
262
- .. code-block :: php
252
+ the same ``getAuthorEmail() `` logic you used above::
263
253
264
254
namespace AppBundle\Security;
265
255
@@ -313,9 +303,7 @@ To enable the security voter in the application, define a new service:
313
303
tags :
314
304
- { name: security.voter }
315
305
316
- Now, you can use the voter with the ``@Security `` annotation:
317
-
318
- .. code-block :: php
306
+ Now, you can use the voter with the ``@Security `` annotation::
319
307
320
308
/**
321
309
* @Route("/{id}/edit", name="admin_post_edit")
@@ -327,9 +315,7 @@ Now, you can use the voter with the ``@Security`` annotation:
327
315
}
328
316
329
317
You can also use this directly with the ``security.authorization_checker `` service or
330
- via the even easier shortcut in a controller:
331
-
332
- .. code-block :: php
318
+ via the even easier shortcut in a controller::
333
319
334
320
/**
335
321
* @Route("/{id}/edit", name="admin_post_edit")
0 commit comments