Skip to content

Commit dc7271a

Browse files
committed
minor #9339 Use the shorthand notation when applicable (greg0ire)
This PR was squashed before being merged into the 2.7 branch (closes #9339). Discussion ---------- Use the shorthand notation when applicable It's part of the standard Commits ------- d8faa39 Use the shorthand notation when applicable
2 parents a34ed7d + d8faa39 commit dc7271a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+80
-234
lines changed

best_practices/business-logic.rst

+4-12
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ The blog application needs a utility that can transform a post title (e.g.
5757
part of the post URL.
5858

5959
Let's create a new ``Slugger`` class inside ``src/AppBundle/Utils/`` and
60-
add the following ``slugify()`` method:
61-
62-
.. code-block:: php
60+
add the following ``slugify()`` method::
6361

6462
// src/AppBundle/Utils/Slugger.php
6563
namespace AppBundle\Utils;
@@ -96,9 +94,7 @@ your code will be easier to read and use.
9694
you ever need to.
9795

9896
Now you can use the custom slugger in any controller class, such as the
99-
``AdminController``:
100-
101-
.. code-block:: php
97+
``AdminController``::
10298

10399
public function createAction(Request $request)
104100
{
@@ -203,9 +199,7 @@ PHP and annotations.
203199
Use annotations to define the mapping information of the Doctrine entities.
204200

205201
Annotations are by far the most convenient and agile way of setting up and
206-
looking for mapping information:
207-
208-
.. code-block:: php
202+
looking for mapping information::
209203

210204
namespace AppBundle\Entity;
211205

@@ -284,9 +278,7 @@ the following command to install the Doctrine fixtures bundle:
284278
$ composer require "doctrine/doctrine-fixtures-bundle"
285279
286280
Then, enable the bundle in ``AppKernel.php``, but only for the ``dev`` and
287-
``test`` environments:
288-
289-
.. code-block:: php
281+
``test`` environments::
290282

291283
use Symfony\Component\HttpKernel\Kernel;
292284

best_practices/configuration.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ Constants can be used for example in your Twig templates thanks to the
133133
</p>
134134

135135
And Doctrine entities and repositories can now easily access these values,
136-
whereas they cannot access the container parameters:
137-
138-
.. code-block:: php
136+
whereas they cannot access the container parameters::
139137

140138
namespace AppBundle\Repository;
141139

best_practices/controllers.rst

+4-12
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ What does the Controller look like
8989
----------------------------------
9090

9191
Considering all this, here is an example of what the controller should look like
92-
for the homepage of our app:
93-
94-
.. code-block:: php
92+
for the homepage of our app::
9593

9694
namespace AppBundle\Controller;
9795

@@ -129,9 +127,7 @@ to automatically query for an entity and pass it as an argument to your controll
129127
Use the ParamConverter trick to automatically query for Doctrine entities
130128
when it's simple and convenient.
131129

132-
For example:
133-
134-
.. code-block:: php
130+
For example::
135131

136132
use AppBundle\Entity\Post;
137133
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -161,9 +157,7 @@ When Things Get More Advanced
161157
The above example works without any configuration because the wildcard name ``{id}`` matches
162158
the name of the property on the entity. If this isn't true, or if you have
163159
even more complex logic, the easiest thing to do is just query for the entity
164-
manually. In our application, we have this situation in ``CommentController``:
165-
166-
.. code-block:: php
160+
manually. In our application, we have this situation in ``CommentController``::
167161

168162
/**
169163
* @Route("/comment/{postSlug}/new", name="comment_new")
@@ -182,9 +176,7 @@ manually. In our application, we have this situation in ``CommentController``:
182176
}
183177

184178
You can also use the ``@ParamConverter`` configuration, which is infinitely
185-
flexible:
186-
187-
.. code-block:: php
179+
flexible::
188180

189181
use AppBundle\Entity\Post;
190182
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

best_practices/forms.rst

+2-6
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ makes them easier to re-use later.
9494

9595
Since Symfony 2.3, you can add buttons as fields on your form. This is a nice
9696
way to simplify the template that renders your form. But if you add the buttons
97-
directly in your form class, this would effectively limit the scope of that form:
98-
99-
.. code-block:: php
97+
directly in your form class, this would effectively limit the scope of that form::
10098

10199
class PostType extends AbstractType
102100
{
@@ -178,9 +176,7 @@ can control *how* the form renders at a global level using form theming.
178176
Handling Form Submits
179177
---------------------
180178

181-
Handling a form submit usually follows a similar template:
182-
183-
.. code-block:: php
179+
Handling a form submit usually follows a similar template::
184180

185181
public function newAction(Request $request)
186182
{

best_practices/security.rst

+7-21
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ Using Expressions for Complex Security Restrictions
130130
If your security logic is a little bit more complex, you can use an :doc:`expression </components/expression_language>`
131131
inside ``@Security``. In the following example, a user can only access the
132132
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::
136134

137135
use AppBundle\Entity\Post;
138136
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -163,9 +161,7 @@ need to repeat the expression code using Twig syntax:
163161
{% endif %}
164162

165163
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::
169165

170166
// src/AppBundle/Entity/Post.php
171167
// ...
@@ -185,9 +181,7 @@ to the ``Post`` entity that checks if a given user is its author:
185181
}
186182
}
187183

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::
191185

192186
use AppBundle\Entity\Post;
193187
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -217,9 +211,7 @@ Checking Permissions without @Security
217211
The above example with ``@Security`` only works because we're using the
218212
:ref:`ParamConverter <best-practices-paramconverter>`, which gives the expression
219213
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::
223215

224216
/**
225217
* @Route("/{id}/edit", name="admin_post_edit")
@@ -257,9 +249,7 @@ of magnitude easier than :doc:`ACLs </security/acl>` and will give
257249
you the flexibility you need in almost all cases.
258250

259251
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::
263253

264254
namespace AppBundle\Security;
265255

@@ -313,9 +303,7 @@ To enable the security voter in the application, define a new service:
313303
tags:
314304
- { name: security.voter }
315305
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::
319307

320308
/**
321309
* @Route("/{id}/edit", name="admin_post_edit")
@@ -327,9 +315,7 @@ Now, you can use the voter with the ``@Security`` annotation:
327315
}
328316

329317
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::
333319

334320
/**
335321
* @Route("/{id}/edit", name="admin_post_edit")

best_practices/templates.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ Markdown content into HTML::
115115

116116
Next, create a new Twig extension and define a new filter called ``md2html``
117117
using the ``Twig_SimpleFilter`` class. Inject the newly defined ``markdown``
118-
service in the constructor of the Twig extension:
119-
120-
.. code-block:: php
118+
service in the constructor of the Twig extension::
121119

122120
namespace AppBundle\Twig;
123121

best_practices/tests.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ generator service:
8080
generator.
8181

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

8785
public function testBlogArchives()
8886
{

components/config/definition.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,7 @@ Documenting the Option
417417

418418
All options can be documented using the
419419
:method:`Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::info`
420-
method.
421-
422-
.. code-block:: php
420+
method::
423421

424422
$rootNode
425423
->children()

components/dom_crawler.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ The crawler supports multiple ways of adding the content::
260260

261261
As the Crawler's implementation is based on the DOM extension, it is also able
262262
to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList`
263-
and :phpclass:`DOMNode` objects:
264-
265-
.. code-block:: php
263+
and :phpclass:`DOMNode` objects::
266264

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

components/expression_language/extending.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ This interface requires one method:
6868
:method:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface::getFunctions`,
6969
which returns an array of expression functions (instances of
7070
:class:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunction`) to
71-
register.
72-
73-
.. code-block:: php
71+
register::
7472

7573
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
7674
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

components/filesystem/lock_handler.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ Usage
2222
The lock handler only works if you're using just one server. If you have
2323
several hosts, you must not use this helper.
2424

25-
A lock can be used, for example, to allow only one instance of a command to run.
26-
27-
.. code-block:: php
25+
A lock can be used, for example, to allow only one instance of a command to run::
2826

2927
use Symfony\Component\Filesystem\LockHandler;
3028

components/http_foundation/trusting_proxies.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ the actual host may be stored in an ``X-Forwarded-Host`` header.
1717

1818
Since HTTP headers can be spoofed, Symfony does *not* trust these proxy
1919
headers by default. If you are behind a proxy, you should manually whitelist
20-
your proxy as follows:
21-
22-
.. code-block:: php
20+
your proxy as follows::
2321

2422
use Symfony\Component\HttpFoundation\Request;
2523

components/process.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ Process Pid
310310
The ``getPid()`` method was introduced in Symfony 2.3.
311311

312312
You can access the `pid`_ of a running process with the
313-
:method:`Symfony\\Component\\Process\\Process::getPid` method.
314-
315-
.. code-block:: php
313+
:method:`Symfony\\Component\\Process\\Process::getPid` method::
316314

317315
use Symfony\Component\Process\Process;
318316

components/templating.rst

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

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

components/translation.rst

+1-3
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

+4-12
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ Reading YAML Files
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

@@ -113,9 +111,7 @@ string and converts it to a PHP array:
113111
If an error occurs during parsing, the parser throws a
114112
:class:`Symfony\\Component\\Yaml\\Exception\\ParseException` exception
115113
indicating the error type and the line in the original YAML string where the
116-
error occurred:
117-
118-
.. code-block:: php
114+
error occurred::
119115

120116
use Symfony\Component\Yaml\Exception\ParseException;
121117

@@ -145,9 +141,7 @@ Writing YAML Files
145141
~~~~~~~~~~~~~~~~~~
146142

147143
The :method:`Symfony\\Component\\Yaml\\Yaml::dump` method dumps any PHP
148-
array to its YAML representation:
149-
150-
.. code-block:: php
144+
array to its YAML representation::
151145

152146
use Symfony\Component\Yaml\Yaml;
153147

@@ -179,9 +173,7 @@ representation:
179173
180174
The second argument of the :method:`Symfony\\Component\\Yaml\\Yaml::dump`
181175
method customizes the level at which the output switches from the expanded
182-
representation to the inline one:
183-
184-
.. code-block:: php
176+
representation to the inline one::
185177

186178
echo Yaml::dump($array, 1);
187179

components/yaml/yaml_format.rst

+3-9
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

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ are used:
3131
* for the ``test`` environment: ``app/config/config_test.yml``
3232

3333
This works via a simple standard that's used by default inside the ``AppKernel``
34-
class:
35-
36-
.. code-block:: php
34+
class::
3735

3836
// app/AppKernel.php
3937

0 commit comments

Comments
 (0)