Skip to content

Commit c3cd8e8

Browse files
committed
Merge branch '4.0'
* 4.0: Use the shorthand notation when applicable
2 parents a71085e + cfce3d9 commit c3cd8e8

33 files changed

+57
-163
lines changed

best_practices/business-logic.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ as Twig extensions, event subscribers, etc.
4343

4444
The blog application needs a utility that can transform a post title (e.g.
4545
"Hello World") into a slug (e.g. "hello-world") to include it as part of the
46-
post URL. Let's create a new ``Slugger`` class inside ``src/Utils/``:
47-
48-
.. code-block:: php
46+
post URL. Let's create a new ``Slugger`` class inside ``src/Utils/``::
4947

5048
// src/Utils/Slugger.php
5149
namespace App\Utils;
@@ -69,9 +67,7 @@ simply ``Slugger::class`` if the class is already imported in your code).
6967
case, use a snake case id).
7068

7169
Now you can use the custom slugger in any other service or controller class,
72-
such as the ``AdminController``:
73-
74-
.. code-block:: php
70+
such as the ``AdminController``::
7571

7672
use App\Utils\Slugger;
7773

@@ -152,9 +148,7 @@ PHP and annotations.
152148
Use annotations to define the mapping information of the Doctrine entities.
153149

154150
Annotations are by far the most convenient and agile way of setting up and
155-
looking for mapping information:
156-
157-
.. code-block:: php
151+
looking for mapping information::
158152

159153
namespace App\Entity;
160154

@@ -233,9 +227,7 @@ the following command to install the Doctrine fixtures bundle:
233227
$ composer require "doctrine/doctrine-fixtures-bundle"
234228
235229
Then, this bundle is enabled automatically, but only for the ``dev`` and
236-
``test`` environments:
237-
238-
.. code-block:: php
230+
``test`` environments::
239231

240232
// config/bundles.php
241233

best_practices/configuration.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ Constants can be used for example in your Twig templates thanks to the
135135
</p>
136136

137137
And Doctrine entities and repositories can now easily access these values,
138-
whereas they cannot access the container parameters:
139-
140-
.. code-block:: php
138+
whereas they cannot access the container parameters::
141139

142140
namespace App\Repository;
143141

best_practices/controllers.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ What does the Controller look like
9898
----------------------------------
9999

100100
Considering all this, here is an example of what the controller should look like
101-
for the homepage of our app:
102-
103-
.. code-block:: php
101+
for the homepage of our app::
104102

105103
namespace App\Controller;
106104

@@ -154,9 +152,7 @@ to automatically query for an entity and pass it as an argument to your controll
154152
Use the ParamConverter trick to automatically query for Doctrine entities
155153
when it's simple and convenient.
156154

157-
For example:
158-
159-
.. code-block:: php
155+
For example::
160156

161157
use App\Entity\Post;
162158
use Symfony\Component\Routing\Annotation\Route;
@@ -187,9 +183,7 @@ The above example works without any configuration because the wildcard name
187183
``{id}`` matches the name of the property on the entity. If this isn't true, or
188184
if you have even more complex logic, the easiest thing to do is just query for
189185
the entity manually. In our application, we have this situation in
190-
``CommentController``:
191-
192-
.. code-block:: php
186+
``CommentController``::
193187

194188
/**
195189
* @Route("/comment/{postSlug}/new", name="comment_new")
@@ -208,9 +202,7 @@ the entity manually. In our application, we have this situation in
208202
}
209203

210204
You can also use the ``@ParamConverter`` configuration, which is infinitely
211-
flexible:
212-
213-
.. code-block:: php
205+
flexible::
214206

215207
use App\Entity\Post;
216208
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

best_practices/forms.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ makes them easier to re-use later.
8080
The Symfony Form component allows you to add buttons as fields on your form.
8181
This is a nice way to simplify the template that renders your form. But if you
8282
add the buttons directly in your form class, this would effectively limit the
83-
scope of that form:
84-
85-
.. code-block:: php
83+
scope of that form::
8684

8785
class PostType extends AbstractType
8886
{
@@ -164,9 +162,7 @@ can control *how* the form renders at a global level using form theming.
164162
Handling Form Submits
165163
---------------------
166164

167-
Handling a form submit usually follows a similar template:
168-
169-
.. code-block:: php
165+
Handling a form submit usually follows a similar template::
170166

171167
public function new(Request $request)
172168
{

best_practices/security.rst

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ Using Expressions for Complex Security Restrictions
134134
If your security logic is a little bit more complex, you can use an :doc:`expression </components/expression_language>`
135135
inside ``@Security``. In the following example, a user can only access the
136136
controller if their email matches the value returned by the ``getAuthorEmail()``
137-
method on the ``Post`` object:
138-
139-
.. code-block:: php
137+
method on the ``Post`` object::
140138

141139
use App\Entity\Post;
142140
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -167,9 +165,7 @@ need to repeat the expression code using Twig syntax:
167165
{% endif %}
168166

169167
The easiest solution - if your logic is simple enough - is to add a new method
170-
to the ``Post`` entity that checks if a given user is its author:
171-
172-
.. code-block:: php
168+
to the ``Post`` entity that checks if a given user is its author::
173169

174170
// src/Entity/Post.php
175171
// ...
@@ -189,9 +185,7 @@ to the ``Post`` entity that checks if a given user is its author:
189185
}
190186
}
191187

192-
Now you can reuse this method both in the template and in the security expression:
193-
194-
.. code-block:: php
188+
Now you can reuse this method both in the template and in the security expression::
195189

196190
use App\Entity\Post;
197191
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -222,9 +216,7 @@ Checking Permissions without @Security
222216
The above example with ``@Security`` only works because we're using the
223217
:ref:`ParamConverter <best-practices-paramconverter>`, which gives the expression
224218
access to the ``post`` variable. If you don't use this, or have some other
225-
more advanced use-case, you can always do the same security check in PHP:
226-
227-
.. code-block:: php
219+
more advanced use-case, you can always do the same security check in PHP::
228220

229221
/**
230222
* @Route("/{id}/edit", name="admin_post_edit")
@@ -271,9 +263,7 @@ If your security logic is complex and can't be centralized into a method like
271263
all cases.
272264

273265
First, create a voter class. The following example shows a voter that implements
274-
the same ``getAuthorEmail()`` logic you used above:
275-
276-
.. code-block:: php
266+
the same ``getAuthorEmail()`` logic you used above::
277267

278268
namespace App\Security;
279269

@@ -345,9 +335,7 @@ your application will :ref:`autoconfigure <services-autoconfigure>` your securit
345335
voter and inject an ``AccessDecisionManagerInterface`` instance into it thanks to
346336
:doc:`autowiring </service_container/autowiring>`.
347337

348-
Now, you can use the voter with the ``@Security`` annotation:
349-
350-
.. code-block:: php
338+
Now, you can use the voter with the ``@Security`` annotation::
351339

352340
/**
353341
* @Route("/{id}/edit", name="admin_post_edit")
@@ -359,9 +347,7 @@ Now, you can use the voter with the ``@Security`` annotation:
359347
}
360348

361349
You can also use this directly with the ``security.authorization_checker`` service or
362-
via the even easier shortcut in a controller:
363-
364-
.. code-block:: php
350+
via the even easier shortcut in a controller::
365351

366352
/**
367353
* @Route("/{id}/edit", name="admin_post_edit")

best_practices/templates.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ to define one single method to transform Markdown content into HTML::
7575

7676
Next, create a new Twig extension and define a filter called ``md2html`` using
7777
the ``TwigFilter`` class. Inject the newly defined ``Markdown`` class in the
78-
constructor of the Twig extension:
79-
80-
.. code-block:: php
78+
constructor of the Twig extension::
8179

8280
namespace App\Twig;
8381

best_practices/tests.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ generator service:
7979
generator.
8080

8181
Consider the following functional test that uses the ``router`` service to
82-
generate the URL of the tested page:
83-
84-
.. code-block:: php
82+
generate the URL of the tested page::
8583

8684
// ...
8785
private $router; // consider that this holds the Symfony router service

components/config/definition.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,7 @@ Documenting the Option
452452

453453
All options can be documented using the
454454
:method:`Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::info`
455-
method.
456-
457-
.. code-block:: php
455+
method::
458456

459457
$rootNode
460458
->children()

components/dom_crawler.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ The crawler supports multiple ways of adding the content::
248248

249249
As the Crawler's implementation is based on the DOM extension, it is also able
250250
to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList`
251-
and :phpclass:`DOMNode` objects:
252-
253-
.. code-block:: php
251+
and :phpclass:`DOMNode` objects::
254252

255253
$domDocument = new \DOMDocument();
256254
$domDocument->loadXml('<root><node /><node /></root>');

components/expression_language/extending.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ This interface requires one method:
6565
:method:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface::getFunctions`,
6666
which returns an array of expression functions (instances of
6767
:class:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunction`) to
68-
register.
69-
70-
.. code-block:: php
68+
register::
7169

7270
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
7371
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

0 commit comments

Comments
 (0)