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;

components/process.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ Process Pid
369369
-----------
370370

371371
You can access the `pid`_ of a running process with the
372-
:method:`Symfony\\Component\\Process\\Process::getPid` method.
373-
374-
.. code-block:: php
372+
:method:`Symfony\\Component\\Process\\Process::getPid` method::
375373

376374
use Symfony\Component\Process\Process;
377375

components/templating.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ takes a list of engines and acts just like a normal templating engine. The
187187
only difference is that it delegates the calls to one of the other engines. To
188188
choose which one to use for the template, the
189189
:method:`EngineInterface::supports() <Symfony\\Component\\Templating\\EngineInterface::supports>`
190-
method is used.
191-
192-
.. code-block:: php
190+
method is used::
193191

194192
use Acme\Templating\CustomEngine;
195193
use Symfony\Component\Templating\PhpEngine;

components/translation.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ catalogs*).
2929
Configuration
3030
~~~~~~~~~~~~~
3131

32-
The constructor of the ``Translator`` class needs one argument: The locale.
33-
34-
.. code-block:: php
32+
The constructor of the ``Translator`` class needs one argument: The locale::
3533

3634
use Symfony\Component\Translation\Translator;
3735

components/yaml.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ Reading YAML Contents
9696
~~~~~~~~~~~~~~~~~~~~~
9797

9898
The :method:`Symfony\\Component\\Yaml\\Yaml::parse` method parses a YAML
99-
string and converts it to a PHP array:
100-
101-
.. code-block:: php
99+
string and converts it to a PHP array::
102100

103101
use Symfony\Component\Yaml\Yaml;
104102

@@ -108,9 +106,7 @@ string and converts it to a PHP array:
108106
If an error occurs during parsing, the parser throws a
109107
:class:`Symfony\\Component\\Yaml\\Exception\\ParseException` exception
110108
indicating the error type and the line in the original YAML string where the
111-
error occurred:
112-
113-
.. code-block:: php
109+
error occurred::
114110

115111
use Symfony\Component\Yaml\Exception\ParseException;
116112

@@ -138,9 +134,7 @@ Writing YAML Files
138134
~~~~~~~~~~~~~~~~~~
139135

140136
The :method:`Symfony\\Component\\Yaml\\Yaml::dump` method dumps any PHP
141-
array to its YAML representation:
142-
143-
.. code-block:: php
137+
array to its YAML representation::
144138

145139
use Symfony\Component\Yaml\Yaml;
146140

@@ -172,9 +166,7 @@ representation:
172166
173167
The second argument of the :method:`Symfony\\Component\\Yaml\\Yaml::dump`
174168
method customizes the level at which the output switches from the expanded
175-
representation to the inline one:
176-
177-
.. code-block:: php
169+
representation to the inline one::
178170

179171
echo Yaml::dump($array, 1);
180172

components/yaml/yaml_format.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ Sequences use a dash followed by a space:
177177
- Perl
178178
- Python
179179
180-
The previous YAML file is equivalent to the following PHP code:
181-
182-
.. code-block:: php
180+
The previous YAML file is equivalent to the following PHP code::
183181

184182
array('PHP', 'Perl', 'Python');
185183

@@ -191,9 +189,7 @@ Mappings use a colon followed by a space (``:`` ) to mark each key/value pair:
191189
MySQL: 5.1
192190
Apache: 2.2.20
193191
194-
which is equivalent to this PHP code:
195-
196-
.. code-block:: php
192+
which is equivalent to this PHP code::
197193

198194
array('PHP' => 5.2, 'MySQL' => 5.1, 'Apache' => '2.2.20');
199195

@@ -220,9 +216,7 @@ YAML uses indentation with one or more spaces to describe nested collections:
220216
PHP: 5.2
221217
Propel: 1.3
222218
223-
The above YAML is equivalent to the following PHP code:
224-
225-
.. code-block:: php
219+
The above YAML is equivalent to the following PHP code::
226220

227221
array(
228222
'symfony 1.0' => array(

configuration/environments.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ In reality, each environment differs only somewhat from others. This means that
3333
all environments share a large base of common configurations. This configuration
3434
is put in files directly in the ``config/packages/`` directory.
3535

36-
The location of these files is defined by the application's Kernel::
36+
The location of these files is defined by the application's kernel::
3737

3838
// src/Kernel.php
3939

configuration/external_parameters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This variable is referenced in the service container configuration using
6161
6262
</container>
6363
64-
.. code-block:: php
64+
::
6565

6666
// config/packages/doctrine.php
6767
$container->loadFromExtension('doctrine', array(

contributing/documentation/standards.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Sphinx
1313
* Each line should break approximately after the first word that crosses the
1414
72nd character (so most lines end up being 72-78 characters);
1515
* The ``::`` shorthand is *preferred* over ``.. code-block:: php`` to begin a PHP
16-
code block (read `the Sphinx documentation`_ to see when you should use the
17-
shorthand);
16+
code block unless it results in the marker being on its own line (read
17+
`the Sphinx documentation`_ to see when you should use the shorthand);
1818
* Inline hyperlinks are **not** used. Separate the link and their target
1919
definition, which you add on the bottom of the page;
2020
* Inline markup should be closed on the same line as the open-string;

0 commit comments

Comments
 (0)