Skip to content

Commit 8465e85

Browse files
committed
Merge branch '2.8'
2 parents d8db51a + 0b3985d commit 8465e85

File tree

22 files changed

+500
-421
lines changed

22 files changed

+500
-421
lines changed

book/controller.rst

+39-16
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
440440
}
441441

442442
.. versionadded:: 2.6
443-
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you
443+
The ``redirectToRoute()`` method was introduced in Symfony 2.6. Previously (and still now), you
444444
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).
445445

446446
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::
@@ -619,12 +619,12 @@ session.
619619
Flash Messages
620620
~~~~~~~~~~~~~~
621621

622-
You can also store small messages that will be stored on the user's session.
623-
This is useful when processing a form:
624-
you want to redirect and have a special message shown on the *next* page.
625-
These types of messages are called "flash" messages.
622+
You can also store special messages, called "flash" messages, on the user's
623+
session. By design, flash messages are meant to be used exactly once: they vanish
624+
from the session automatically as soon as you retrieve them. This feature makes
625+
"flash" messages particularly great for storing user notifications.
626626

627-
For example, imagine you're processing a form submit::
627+
For example, imagine you're processing a form submission::
628628

629629
use Symfony\Component\HttpFoundation\Request;
630630

@@ -650,20 +650,20 @@ For example, imagine you're processing a form submit::
650650
return $this->render(...);
651651
}
652652

653-
After processing the request, the controller sets a ``notice`` flash message
654-
in the session and then redirects. The name (``notice``) isn't significant -
655-
it's just something you invent and reference next.
653+
After processing the request, the controller sets a flash message in the session
654+
and then redirects. The message key (``notice`` in this example) can be anything:
655+
you'll use this key to retrieve the message.
656656

657-
In the template of the next action, the following code could be used to render
658-
the ``notice`` message:
657+
In the template of the next page (or even better, in your base layout template),
658+
read any flash messages from the session::
659659

660660
.. configuration-block::
661661

662662
.. code-block:: html+jinja
663663

664-
{% for flashMessage in app.session.flashbag.get('notice') %}
664+
{% for flash_message in app.session.flashbag.get('notice') %}
665665
<div class="flash-notice">
666-
{{ flashMessage }}
666+
{{ flash_message }}
667667
</div>
668668
{% endfor %}
669669

@@ -677,9 +677,9 @@ the ``notice`` message:
677677

678678
.. note::
679679

680-
By design, flash messages are meant to be processed exactly once. This means
681-
that they vanish from the session automatically when they are retrieved from
682-
the flash bag by calling the ``get()`` method.
680+
It's common to use ``notice``, ``warning`` and ``error`` as the keys of the
681+
different types of flash messages, but you can use any key that fits your
682+
needs.
683683

684684
.. tip::
685685

@@ -811,6 +811,29 @@ Just like when creating a controller for a route, the order of the arguments of
811811
order of the arguments, Symfony will still pass the correct value to each
812812
variable.
813813

814+
Validating a CSRF Token
815+
-----------------------
816+
817+
Sometimes, you want to use CSRF protection in an action where you don't want to
818+
use the Symfony Form component. If, for example, you're doing a DELETE action,
819+
you can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::isCsrfTokenValid`
820+
method to check the CSRF token::
821+
822+
if ($this->isCsrfTokenValid('token_id', $submittedToken)) {
823+
// ... do something, like deleting an object
824+
}
825+
826+
.. versionadded:: 2.6
827+
The ``isCsrfTokenValid()`` shortcut method was introduced in Symfony 2.6.
828+
It is equivalent to executing the following code:
829+
830+
.. code-block:: php
831+
832+
use Symfony\Component\Security\Csrf\CsrfToken;
833+
834+
$this->get('security.csrf.token_manager')
835+
->isTokenValid(new CsrfToken('token_id', 'TOKEN'));
836+
814837
Final Thoughts
815838
--------------
816839

book/installation.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ optional second argument of the ``new`` command:
9898
$ symfony new my_project_name 2.3.26
9999
$ symfony new my_project_name 2.6.5
100100
101-
If you want your project to be based on the latest :ref:`Symfony LTS version <releases-lts>`,
102-
pass ``lts`` as the second argument of the ``new`` command:
101+
# use a beta or RC version (useful for testing new Symfony versions)
102+
$ symfony new my_project 2.7.0-BETA1
103+
$ symfony new my_project 2.7.0-RC1
104+
105+
The installer also supports a special version called ``lts`` which installs the
106+
most recent :ref:`Symfony LTS version <releases-lts>` available:
103107

104108
.. code-block:: bash
105109
106-
# Linux, Mac OS X
107110
$ symfony new my_project_name lts
108111
109-
# Windows
110-
c:\projects\> php symfony new my_project_name lts
111-
112112
Read the :doc:`Symfony Release process </contributing/community/releases>`
113113
to better understand why there are several Symfony versions and which one
114114
to use for your projects.

book/routing.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -1575,9 +1575,13 @@ to ``generate()``:
15751575

15761576
.. code-block:: html+php
15771577

1578+
<?php
1579+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1580+
?>
1581+
15781582
<a href="<?php echo $view['router']->generate('blog_show', array(
15791583
'slug' => 'my-blog-post',
1580-
), true) ?>">
1584+
), UrlGeneratorInterface::ABSOLUTE_URL) ?>">
15811585
Read this blog post.
15821586
</a>
15831587

book/security.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,15 @@ FriendsOfPHP organization.
13781378
any of your dependencies is affected by a known security vulnerability.
13791379
Therefore, you can easily integrate it in your build process.
13801380

1381+
.. note::
1382+
1383+
To enable the ``security:check`` command, make sure the
1384+
`SensioDistributionBundle`_ is installed.
1385+
1386+
.. code-block:: bash
1387+
1388+
$ composer require 'sensio/distribution-bundle'
1389+
13811390
Final Words
13821391
-----------
13831392

@@ -1408,3 +1417,4 @@ Learn More from the Cookbook
14081417
.. _`frameworkextrabundle documentation`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
14091418
.. _`security advisories database`: https://github.com/FriendsOfPHP/security-advisories
14101419
.. _`HWIOAuthBundle`: https://github.com/hwi/HWIOAuthBundle
1420+
.. _`SensioDistributionBundle`: https://packagist.org/packages/sensio/distribution-bundle

book/templating.rst

+47-7
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ you set `with_context`_ to false).
580580
elements, it would look like this: ``{'foo': foo, 'bar': bar}``.
581581

582582
.. versionadded:: 2.3
583-
The `include() function`_ is a new Twig feature that's available in Symfony
584-
2.3. Prior, the `{% include %} tag`_ tag was used.
583+
The `include() function`_ is available since Symfony 2.3. Prior, the
584+
`{% include %} tag`_ was used.
585585

586586
.. index::
587587
single: Templating; Embedding action
@@ -856,6 +856,24 @@ configuration:
856856

857857
.. configuration-block::
858858

859+
.. code-block:: php-annotations
860+
861+
// src/AppBundle/Controller/WelcomeController.php
862+
// ...
863+
864+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
865+
866+
class WelcomeController extends Controller
867+
{
868+
/**
869+
* @Route("/", name="_welcome")
870+
*/
871+
public function indexAction()
872+
{
873+
// ...
874+
}
875+
}
876+
859877
.. code-block:: yaml
860878
861879
# app/config/routing.yml
@@ -907,6 +925,24 @@ route:
907925

908926
.. configuration-block::
909927

928+
.. code-block:: php-annotations
929+
930+
// src/AppBundle/Controller/ArticleController.php
931+
// ...
932+
933+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
934+
935+
class ArticleController extends Controller
936+
{
937+
/**
938+
* @Route("/article/{slug}", name="article_show")
939+
*/
940+
public function showAction($slug)
941+
{
942+
// ...
943+
}
944+
}
945+
910946
.. code-block:: yaml
911947
912948
# app/config/routing.yml
@@ -981,10 +1017,14 @@ correctly:
9811017

9821018
.. code-block:: html+php
9831019

1020+
<?php
1021+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1022+
?>
1023+
9841024
<a href="<?php echo $view['router']->generate(
9851025
'_welcome',
9861026
array(),
987-
true
1027+
UrlGeneratorInterface::ABSOLUTE_URL
9881028
) ?>">Home</a>
9891029

9901030
.. index::
@@ -1029,8 +1069,8 @@ configuration option.
10291069

10301070
.. _`book-templating-version-by-asset`:
10311071

1032-
If you need to set a version for a specific asset, you can set the fourth
1033-
argument (or the ``version`` argument) to the desired version:
1072+
If you need to set a version for a specific asset, you can set the ``version`` argument
1073+
if you are using Twig (or the fourth argument if you are using PHP) to the desired version:
10341074

10351075
.. configuration-block::
10361076

@@ -1051,8 +1091,8 @@ If you don't give a version or pass ``null``, the default package version
10511091
(from :ref:`ref-framework-assets-version`) will be used. If you pass ``false``,
10521092
versioned URL will be deactivated for this asset.
10531093

1054-
If you need absolute URLs for assets, you can set the third argument (or the
1055-
``absolute`` argument) to ``true``:
1094+
If you need absolute URLs for assets, you can set the ``absolute`` argument
1095+
if you are using Twig (or the third argument if you are using PHP) to ``true``:
10561096

10571097
.. configuration-block::
10581098

components/css_selector.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,17 @@ document.
4646
The CssSelector Component
4747
~~~~~~~~~~~~~~~~~~~~~~~~~
4848

49+
.. versionadded:: 2.8
50+
The ``CssSelectorConverter`` class was introduced in Symfony 2.8. Previously,
51+
the ``CssSelector`` class was used and ``toXPath`` was a static method.
52+
4953
The component's only goal is to convert CSS selectors to their XPath
50-
equivalents::
54+
equivalents, using :method:`Symfony\\Component\\CssSelector\\CssSelectorConverter::toXPath`::
5155

52-
use Symfony\Component\CssSelector\CssSelector;
56+
use Symfony\Component\CssSelector\CssSelectorConverter;
5357

54-
var_dump(CssSelector::toXPath('div.item > h4 > a'));
58+
$converter = new CssSelectorConverter();
59+
var_dump($converter->toXPath('div.item > h4 > a'));
5560

5661
This gives the following output:
5762

components/dependency_injection/advanced.rst

+11-13
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ Deprecating Services
226226
The ``deprecated`` setting was introduced in Symfony 2.8.
227227

228228
Once you have decided to deprecate the use of a service (because it is outdated
229-
or you decided not to use and maintain it anymore), you can deprecate its
230-
definition:
229+
or you decided not to maintain it anymore), you can deprecate its definition:
231230

232231
.. configuration-block::
233232

@@ -261,26 +260,25 @@ definition:
261260
)
262261
;
263262
264-
Now, every time a service is created using this deprecated definition, a
265-
deprecation warning will be triggered, advising you to stop or to change your
266-
uses of that service.
263+
Now, every time this service is used, a deprecation warning is triggered,
264+
advising you to stop or to change your uses of that service.
267265

268-
The message is actually a message template, which will replace occurrences
269-
of the ``%service_id%`` by the service's id. You **must** have at least one
266+
The message is actually a message template, which replaces occurrences of the
267+
``%service_id%`` placeholder by the service's id. You **must** have at least one
270268
occurrence of the ``%service_id%`` placeholder in your template.
271269

272270
.. note::
273271

274-
The deprecation message is optional. If not set, Symfony will show a default
275-
message ``The "%service_id%" service is deprecated. You should stop using it,
272+
The deprecation message is optional. If not set, Symfony will show this default
273+
message: ``The "%service_id%" service is deprecated. You should stop using it,
276274
as it will soon be removed.``.
277275

278276
.. tip::
279277

280-
It is strongly recommended that you fill the message template, to avoid a
281-
message that could be too generic such as the default one. A good message
282-
informs when this service was deprecated, and until when it will be
283-
maintained (look at the examples above).
278+
It is strongly recommended that you define a custom message because the
279+
default one is too generic. A good message informs when this service was
280+
deprecated, until when it will be maintained and the alternative services
281+
to use (if any).
284282

285283
For service decorators (see above), if the definition does not modify the
286284
deprecated status, it will inherit the status from the definition that is

components/dom_crawler.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Anonymous function can be used to filter with more complex criteria::
8787
$crawler = $crawler
8888
->filter('body > p')
8989
->reduce(function (Crawler $node, $i) {
90-
// filter even nodes
90+
// filter every other node
9191
return ($i % 2) == 0;
9292
});
9393

0 commit comments

Comments
 (0)