Skip to content

Commit 4b0ebea

Browse files
committed
Merge branch '2.5' into 2.6
* 2.5: [#4857] Adding missing word thanks to xabbuh Fixing bad english thanks to xabbuh Adding missing words thanks to javiereguiluz [#4643] Minor english changes to make things even smoother (though they were correct before) replace API link for SwiftmailerBundle Update security.rst Update routing.rst don't output message from AuthenticationException Add custom link labels where Cookbook articles titles looked wrong Fix code example Removed a leftover comma in security config sample [#4141] Tweaks to the new form csrf caching entry How to override vendor directory location - fix How to override vendor directory location - fix How to override vendor directory location
2 parents c04ed79 + 3a25b1d commit 4b0ebea

File tree

10 files changed

+78
-47
lines changed

10 files changed

+78
-47
lines changed

best_practices/configuration.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ add an extra layer of configuration that's not needed because you don't need
7474
or want these configuration values to change on each server.
7575

7676
The configuration options defined in the ``config.yml`` file usually vary from
77-
one :doc:`/cookbook/configuration/environments` to another. That's why Symfony
78-
already includes ``app/config/config_dev.yml`` and ``app/config/config_prod.yml``
77+
one :doc:`environment </cookbook/configuration/environments>` to another. That's
78+
why Symfony already includes ``app/config/config_dev.yml`` and ``app/config/config_prod.yml``
7979
files so that you can override specific values for each environment.
8080

8181
Constants vs Configuration Options

best_practices/controllers.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ For example:
139139
140140
use AppBundle\Entity\Post;
141141
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
142-
142+
143143
/**
144144
* @Route("/{id}", name="admin_post_show")
145145
*/
@@ -212,6 +212,7 @@ Pre and Post Hooks
212212
------------------
213213

214214
If you need to execute some code before or after the execution of your controllers,
215-
you can use the EventDispatcher component to :doc:`/cookbook/event_dispatcher/before_after_filters`.
215+
you can use the EventDispatcher component to
216+
:doc:`set up before and after filters </cookbook/event_dispatcher/before_after_filters>`.
216217

217218
.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html

best_practices/forms.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ fields:
165165

166166
If you need more control over how your fields are rendered, then you should
167167
remove the ``form_widget(form)`` function and render your fields individually.
168-
See :doc:`/cookbook/form/form_customization` for more information on this and how
169-
you can control *how* the form renders at a global level using form theming.
168+
See the :doc:`/cookbook/form/form_customization` article for more information
169+
on this and how you can control *how* the form renders at a global level
170+
using form theming.
170171

171172
Handling Form Submits
172173
---------------------

book/routing.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ be added for each parameter. For example:
644644

645645
.. configuration-block::
646646

647-
.. code-block:: php
647+
.. code-block:: php-annotations
648648
649649
// src/AppBundle/Controller/BlogController.php
650650

book/security.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Security
55
========
66

77
Symfony's security system is incredibly powerful, but it can also be confusing
8-
to setup. In this chapter, you'll learn how to setup your application's security
8+
to set up. In this chapter, you'll learn how to set up your application's security
99
step-by-step, from configuring your firewall and how you load users to denying
1010
access and fetching the User object. Depending on what you need, sometimes
1111
the initial setup can be tough. But once it's done, Symfony's security system
@@ -300,7 +300,7 @@ provider, but it's better to think of it as an "in configuration" provider:
300300
memory:
301301
users:
302302
ryan:
303-
password: ryanpass,
303+
password: ryanpass
304304
roles: 'ROLE_USER'
305305
admin:
306306
password: kitten

components/http_kernel/introduction.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,9 @@ as possible to the client (e.g. sending emails).
495495

496496
.. sidebar:: ``kernel.terminate`` in the Symfony Framework
497497

498-
If you use the SwiftmailerBundle with Symfony and use ``memory``
499-
spooling, then the :class:`Symfony\\Bundle\\SwiftmailerBundle\\EventListener\\EmailSenderListener`
500-
is activated, which actually delivers any emails that you scheduled to
501-
send during the request.
498+
If you use the SwiftmailerBundle with Symfony and use ``memory`` spooling,
499+
then the `EmailSenderListener`_ is activated, which actually delivers
500+
any emails that you scheduled to send during the request.
502501

503502
.. _component-http-kernel-kernel-exception:
504503

@@ -714,3 +713,4 @@ look like this::
714713
.. _`SensioFrameworkExtraBundle`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
715714
.. _`@ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
716715
.. _`@Template`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html
716+
.. _`EmailSenderListener`: https://github.com/symfony/SwiftmailerBundle/blob/master/EventListener/EmailSenderListener.php

cookbook/bundles/best_practices.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ API is being used. The following code, would work for *all* users::
369369
// the 2.5 API
370370
$this->context->buildViolation($constraint->message)
371371
->setParameter('%string%', $value)
372-
->addViolation();
373-
);
372+
->addViolation()
373+
;
374374
} else {
375375
// the 2.4 API
376376
$this->context->addViolation(

cookbook/cache/form_csrf_caching.rst

+21-27
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,33 @@ need to be cautious if you try to cache pages with forms including them.
1010
For more information about how CSRF protection works in Symfony, please
1111
check :ref:`CSRF Protection <forms-csrf>`.
1212

13-
Why Reverse Proxy Caches do not Cache these Pages by Default
14-
------------------------------------------------------------
15-
16-
There are many ways to generate unique tokens for each user but in order get
17-
them validated when the form is submitted, you need to store them inside the
18-
PHP Session.
19-
20-
If you are using Varnish or some similar reverse proxy cache and you try to cache
21-
pages containing forms with CSRF token protection, you will see that, by default,
22-
the reverse proxy cache refuses to cache.
23-
24-
This happens because a cookie is sent in order to preserve the PHP session open and
25-
Varnish default behaviour is to not cache HTTP requests with cookies.
26-
27-
If you think about it, if you managed to cache the form you would end up
28-
with many users getting the same token in the form generation. When these
29-
users try to send the form to the server, the CSRF validation will fail for
30-
them because the expected token is stored in their session and different
31-
for each user.
32-
33-
How to Cache Most of the Page and still Be Able to Use CSRF Protection
13+
Why Caching Pages with a CSRF token is Problematic
14+
--------------------------------------------------
15+
16+
Typically, each user is assigned a unique CSRF token, which is stored in
17+
the session for validation. This means that if you *do* cache a page with
18+
a form containing a CSRF token, you'll cache the CSRF token of the *first*
19+
user only. When a user submits the form, the token won't match the token
20+
stored in the session and all users (except for the first) will fail CSRF
21+
validation when submitting the form.
22+
23+
In fact, many reverse proxies (like Varnish) will refuse to cache a page
24+
with a CSRF token. This is because a cookie is sent in order to preserve
25+
the PHP session open and Varnish's default behaviour is to not cache HTTP
26+
requests with cookies.
27+
28+
How to Cache Most of the Page and still be able to Use CSRF Protection
3429
----------------------------------------------------------------------
3530

36-
To cache a page that contains a CSRF token you can use more advanced caching
37-
techniques like `ESI`_ fragments, having a TTL for the full page and embedding
38-
the form inside an ESI tag with no cache at all.
31+
To cache a page that contains a CSRF token, you can use more advanced caching
32+
techniques like :ref:`ESI fragments <edge-side-includes>`, where you cache
33+
the full page and embedding the form inside an ESI tag with no cache at all.
3934

40-
Another option to be able to cache that heavy page would be loading the form
41-
via an uncached AJAX request but cache the rest of the HTML response.
35+
Another option would be to load the form via an uncached AJAX request, but
36+
cache the rest of the HTML response.
4237

4338
Or you can even load just the CSRF token with an AJAX request and replace the
4439
form field value with it.
4540

4641
.. _`Cross-site request forgery`: http://en.wikipedia.org/wiki/Cross-site_request_forgery
47-
.. _`ESI`: http://www.w3.org/TR/esi-lang
4842
.. _`Security CSRF Component`: https://github.com/symfony/security-csrf

cookbook/configuration/override_dir_structure.rst

+35
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,38 @@ file:
154154
155155
$ php app/console cache:clear --env=prod
156156
$ php app/console assetic:dump --env=prod --no-debug
157+
158+
Override the ``vendor`` Directory
159+
---------------------------------
160+
161+
To override the ``vendor`` directory, you need to introduce changes in the
162+
following files:
163+
164+
* ``app/autoload.php``
165+
* ``composer.json``
166+
167+
The change in the ``composer.json`` will look like this:
168+
169+
.. code-block:: json
170+
171+
{
172+
...
173+
"config": {
174+
"bin-dir": "bin",
175+
"vendor-dir": "/some/dir/vendor"
176+
},
177+
...
178+
}
179+
180+
In ``app/autoload.php``, you need to modify the path leading to the ``vendor/autoload.php``
181+
file::
182+
183+
// app/autoload.php
184+
// ...
185+
$loader = require '/some/dir/vendor/autoload.php';
186+
187+
.. tip::
188+
189+
This modification can be of interest if you are working in a virtual environment
190+
and cannot use NFS - for example, if you're running a Symfony app using
191+
Vagrant/VirtualBox in a guest operating system.

cookbook/security/form_login_setup.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ First, enable form login under your firewall:
2525
# app/config/security.yml
2626
security:
2727
# ...
28-
28+
2929
firewalls:
3030
default:
3131
anonymous: ~
@@ -98,7 +98,7 @@ under your ``form_login`` configuration (``/login`` and ``/login_check``):
9898
.. configuration-block::
9999

100100
.. code-block:: php-annotations
101-
101+
102102
// src/AppBundle/Controller/SecurityController.php
103103
// ...
104104
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -165,7 +165,7 @@ form::
165165

166166
// src/AppBundle/Controller/SecurityController.php
167167
// ...
168-
168+
169169
// ADD THIS use STATEMENT above your class
170170
use Symfony\Component\Security\Core\Security;
171171

@@ -182,7 +182,7 @@ form::
182182
$error = $session->get(Security::AUTHENTICATION_ERROR);
183183
$session->remove(Security::AUTHENTICATION_ERROR);
184184
} else {
185-
$error = '';
185+
$error = null;
186186
}
187187

188188
// last username entered by the user
@@ -218,7 +218,7 @@ Finally, create the template:
218218
{# ... you will probably extends your base template, like base.html.twig #}
219219

220220
{% if error %}
221-
<div>{{ error.message }}</div>
221+
<div>{{ error.messageKey|trans(error.messageData) }}</div>
222222
{% endif %}
223223

224224
<form action="{{ path('login_check') }}" method="post">

0 commit comments

Comments
 (0)