Skip to content

Commit 6fbcc28

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: [#5098] Minor fix so controller in dumped apache matches _controller route information above fix code block order Update process.rst [Cookbook] Add warning about Composer dev deps on Heroku Added a note against using the Apache Router Implemented all the changes suggested by reviewers Minor rewording Reviewed Configuration cookbook articles Reviewed Cache cookbook articles
2 parents 00ab55b + 808383b commit 6fbcc28

Some content is hidden

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

57 files changed

+734
-685
lines changed

book/forms.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,6 @@ object.
344344

345345
.. configuration-block::
346346

347-
.. code-block:: yaml
348-
349-
# AppBundle/Resources/config/validation.yml
350-
AppBundle\Entity\Task:
351-
properties:
352-
task:
353-
- NotBlank: ~
354-
dueDate:
355-
- NotBlank: ~
356-
- Type: \DateTime
357-
358347
.. code-block:: php-annotations
359348
360349
// AppBundle/Entity/Task.php
@@ -374,6 +363,17 @@ object.
374363
protected $dueDate;
375364
}
376365
366+
.. code-block:: yaml
367+
368+
# AppBundle/Resources/config/validation.yml
369+
AppBundle\Entity\Task:
370+
properties:
371+
task:
372+
- NotBlank: ~
373+
dueDate:
374+
- NotBlank: ~
375+
- Type: \DateTime
376+
377377
.. code-block:: xml
378378
379379
<!-- AppBundle/Resources/config/validation.xml -->

components/process.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ a command in a sub-process::
3636
The component takes care of the subtle differences between the different platforms
3737
when executing the command.
3838

39-
The ``getOutput()`` method always return the whole content of the standard
39+
The ``getOutput()`` method always returns the whole content of the standard
4040
output of the command and ``getErrorOutput()`` the content of the error
4141
output. Alternatively, the :method:`Symfony\\Component\\Process\\Process::getIncrementalOutput`
4242
and :method:`Symfony\\Component\\Process\\Process::getIncrementalErrorOutput`

cookbook/cache/form_csrf_caching.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ validation when submitting the form.
2222

2323
In fact, many reverse proxies (like Varnish) will refuse to cache a page
2424
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
25+
the PHP session open and Varnish's default behavior is to not cache HTTP
2626
requests with cookies.
2727

2828
How to Cache Most of the Page and still be able to Use CSRF Protection

cookbook/cache/varnish.rst

+30-38
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ cached content fast and including support for :ref:`Edge Side Includes <edge-sid
1515
Make Symfony Trust the Reverse Proxy
1616
------------------------------------
1717

18-
For ESI to work correctly and for the :ref:`X-FORWARDED <varnish-x-forwarded-headers>`
19-
headers to be used, you need to configure Varnish as a
20-
:doc:`trusted proxy </cookbook/request/load_balancer_reverse_proxy>`.
18+
Varnish automatically forwards the IP as ``X-Forwarded-For`` and leaves the
19+
``X-Forwarded-Proto`` header in the request. If you do not configure Varnish as
20+
trusted proxy, Symfony will see all requests as coming through insecure HTTP
21+
connections from the Varnish host instead of the real client.
22+
23+
Remember to configure :ref:`framework.trusted_proxies <reference-framework-trusted-proxies>`
24+
in the Symfony configuration so that Varnish is seen as a trusted proxy and the
25+
:ref:`X-Forwarded <varnish-x-forwarded-headers>` headers are used.
2126

2227
.. _varnish-x-forwarded-headers:
2328

2429
Routing and X-FORWARDED Headers
2530
-------------------------------
2631

27-
To ensure that the Symfony Router generates URLs correctly with Varnish,
28-
a ``X-Forwarded-Port`` header must be present for Symfony to use the
29-
correct port number.
32+
If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append
33+
the port where the PHP application is running when generating absolute URLs,
34+
e.g. ``http://example.com:8080/my/path``. To ensure that the Symfony router
35+
generates URLs correctly with Varnish, add the correct port number in the
36+
``X-Forwarded-Port`` header. This port depends on your setup.
3037

31-
This port depends on your setup. Lets say that external connections come in
32-
on the default HTTP port 80. For HTTPS connections, there is another proxy
33-
(as Varnish does not do HTTPS itself) on the default HTTPS port 443 that
34-
handles the SSL termination and forwards the requests as HTTP requests to
35-
Varnish with a ``X-Forwarded-Proto`` header. In this case, you need to add
36-
the following configuration snippet:
38+
Suppose that external connections come in on the default HTTP port 80. For HTTPS
39+
connections, there is another proxy (as Varnish does not do HTTPS itself) on the
40+
default HTTPS port 443 that handles the SSL termination and forwards the requests
41+
as HTTP requests to Varnish with a ``X-Forwarded-Proto`` header. In this case,
42+
add the following to your Varnish configuration:
3743

3844
.. code-block:: varnish4
3945
@@ -45,45 +51,30 @@ the following configuration snippet:
4551
}
4652
}
4753
48-
.. note::
49-
50-
Remember to configure :ref:`framework.trusted_proxies <reference-framework-trusted-proxies>`
51-
in the Symfony configuration so that Varnish is seen as a trusted proxy
52-
and the ``X-Forwarded-*`` headers are used.
53-
54-
Varnish automatically forwards the IP as ``X-Forwarded-For`` and leaves
55-
the ``X-Forwarded-Proto`` header in the request. If you do not configure
56-
Varnish as trusted proxy, Symfony will see all requests as coming through
57-
insecure HTTP connections from the Varnish host instead of the real client.
58-
59-
If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append
60-
the port where the PHP application is running when generating absolute URLs,
61-
e.g. ``http://example.com:8080/my/path``.
62-
6354
Cookies and Caching
6455
-------------------
6556

6657
By default, a sane caching proxy does not cache anything when a request is sent
67-
with :ref:`cookies or a basic authentication header<http-cache-introduction>`.
58+
with :ref:`cookies or a basic authentication header <http-cache-introduction>`.
6859
This is because the content of the page is supposed to depend on the cookie
6960
value or authentication header.
7061

7162
If you know for sure that the backend never uses sessions or basic
72-
authentication, have varnish remove the corresponding header from requests to
63+
authentication, have Varnish remove the corresponding header from requests to
7364
prevent clients from bypassing the cache. In practice, you will need sessions
7465
at least for some parts of the site, e.g. when using forms with
7566
:ref:`CSRF Protection <forms-csrf>`. In this situation, make sure to
7667
:doc:`only start a session when actually needed </cookbook/session/avoid_session_start>`
7768
and clear the session when it is no longer needed. Alternatively, you can look
7869
into :doc:`/cookbook/cache/form_csrf_caching`.
7970

80-
Cookies created in Javascript and used only in the frontend, e.g. when using
81-
Google analytics are nonetheless sent to the server. These cookies are not
71+
Cookies created in JavaScript and used only in the frontend, e.g. when using
72+
Google Analytics, are nonetheless sent to the server. These cookies are not
8273
relevant for the backend and should not affect the caching decision. Configure
8374
your Varnish cache to `clean the cookies header`_. You want to keep the
8475
session cookie, if there is one, and get rid of all other cookies so that pages
8576
are cached if there is no active session. Unless you changed the default
86-
configuration of PHP, your session cookie has the name PHPSESSID:
77+
configuration of PHP, your session cookie has the name ``PHPSESSID``:
8778

8879
.. code-block:: varnish4
8980
@@ -110,8 +101,8 @@ configuration of PHP, your session cookie has the name PHPSESSID:
110101
implemented and explained by the FOSHttpCacheBundle_ under the name
111102
`User Context`_.
112103

113-
Ensure Consistent Caching Behaviour
114-
-----------------------------------
104+
Ensure Consistent Caching Behavior
105+
----------------------------------
115106

116107
Varnish uses the cache headers sent by your application to determine how
117108
to cache content. However, versions prior to Varnish 4 did not respect
@@ -143,7 +134,7 @@ using Varnish 3:
143134
Enable Edge Side Includes (ESI)
144135
-------------------------------
145136

146-
As explained in the :ref:`Edge Side Includes section<edge-side-includes>`,
137+
As explained in the :ref:`Edge Side Includes section <edge-side-includes>`,
147138
Symfony detects whether it talks to a reverse proxy that understands ESI or
148139
not. When you use the Symfony reverse proxy, you don't need to do anything.
149140
But to make Varnish instead of Symfony resolve the ESI tags, you need some
@@ -168,10 +159,11 @@ application:
168159
169160
.. note::
170161

171-
The ``abc`` part of the header isn't important unless you have multiple "surrogates"
172-
that need to advertise their capabilities. See `Surrogate-Capability Header`_ for details.
162+
The ``abc`` part of the header isn't important unless you have multiple
163+
"surrogates" that need to advertise their capabilities. See
164+
`Surrogate-Capability Header`_ for details.
173165

174-
Then, optimize Varnish so that it only parses the Response contents when there
166+
Then, optimize Varnish so that it only parses the response contents when there
175167
is at least one ESI tag by checking the ``Surrogate-Control`` header that
176168
Symfony adds automatically:
177169

cookbook/configuration/apache_router.rst

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
How to Use the Apache Router
55
============================
66

7-
Symfony, while fast out of the box, also provides various ways to increase that speed with a little bit of tweaking.
8-
One of these ways is by letting Apache handle routes directly, rather than using Symfony for this task.
7+
.. caution::
8+
9+
**Using the Apache Router is no longer considered a good practice**.
10+
The small increase obtained in the application routing performance is not
11+
worth the hassle of continuously updating the routes configuration.
12+
13+
The Apache Router will be removed in Symfony 3 and it's highly recommended
14+
to not use it in your applications.
15+
16+
Symfony, while fast out of the box, also provides various ways to increase that
17+
speed with a little bit of tweaking. One of these ways is by letting Apache
18+
handle routes directly, rather than using Symfony for this task.
919

1020
.. caution::
1121

@@ -68,20 +78,20 @@ To test that it's working, create a very basic route for the AppBundle:
6878
# app/config/routing.yml
6979
hello:
7080
path: /hello/{name}
71-
defaults: { _controller: AppBundle:Demo:hello }
81+
defaults: { _controller: AppBundle:Greet:hello }
7282
7383
.. code-block:: xml
7484
7585
<!-- app/config/routing.xml -->
7686
<route id="hello" path="/hello/{name}">
77-
<default key="_controller">AppBundle:Demo:hello</default>
87+
<default key="_controller">AppBundle:Greet:hello</default>
7888
</route>
7989
8090
.. code-block:: php
8191
8292
// app/config/routing.php
8393
$collection->add('hello', new Route('/hello/{name}', array(
84-
'_controller' => 'AppBundle:Demo:hello',
94+
'_controller' => 'AppBundle:Greet:hello',
8595
)));
8696
8797
Now generate the mod_rewrite rules:
@@ -100,7 +110,7 @@ Which should roughly output the following:
100110
101111
# hello
102112
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$
103-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello]
113+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Greet\:hello]
104114
105115
You can now rewrite ``web/.htaccess`` to use the new rules, so with this example
106116
it should look like this:
@@ -116,12 +126,13 @@ it should look like this:
116126
117127
# hello
118128
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$
119-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello]
129+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Greet\:hello]
120130
</IfModule>
121131
122132
.. note::
123133

124-
The procedure above should be done each time you add/change a route if you want to take full advantage of this setup.
134+
The procedure above should be done each time you add/change a route if you
135+
want to take full advantage of this setup.
125136

126137
That's it!
127138
You're now all set to use Apache routes.

cookbook/configuration/environments.rst

+20-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Different Environments, different Configuration Files
2020
-----------------------------------------------------
2121

2222
A typical Symfony application begins with three environments: ``dev``,
23-
``prod``, and ``test``. As discussed, each "environment" simply represents
23+
``prod``, and ``test``. As mentioned, each environment simply represents
2424
a way to execute the same codebase with different configuration. It should
2525
be no surprise then that each environment loads its own individual configuration
2626
file. If you're using the YAML configuration format, the following files
@@ -55,8 +55,8 @@ multiple environments in an elegant, powerful and transparent way.
5555

5656
Of course, in reality, each environment differs only somewhat from others.
5757
Generally, all environments will share a large base of common configuration.
58-
Opening the "dev" configuration file, you can see how this is accomplished
59-
easily and transparently:
58+
Opening the ``config_dev.yml`` configuration file, you can see how this is
59+
accomplished easily and transparently:
6060

6161
.. configuration-block::
6262

@@ -86,7 +86,8 @@ simply first imports from a central configuration file (``config.yml``).
8686
The remainder of the file can then deviate from the default configuration
8787
by overriding individual parameters. For example, by default, the ``web_profiler``
8888
toolbar is disabled. However, in the ``dev`` environment, the toolbar is
89-
activated by modifying the default value in the ``dev`` configuration file:
89+
activated by modifying the value of the ``toolbar`` option in the ``config_dev.yml``
90+
configuration file:
9091

9192
.. configuration-block::
9293

@@ -151,9 +152,9 @@ used by each is explicitly set::
151152

152153
// ...
153154

154-
As you can see, the ``prod`` key specifies that this application will run
155-
in the ``prod`` environment. A Symfony application can be executed in any
156-
environment by using this code and changing the environment string.
155+
The ``prod`` key specifies that this application will run in the ``prod``
156+
environment. A Symfony application can be executed in any environment by using
157+
this code and changing the environment string.
157158

158159
.. note::
159160

@@ -325,9 +326,7 @@ The new environment is now accessible via::
325326
certain environments, for debugging purposes, may give too much information
326327
about the application or underlying infrastructure. To be sure these environments
327328
aren't accessible, the front controller is usually protected from external
328-
IP addresses via the following code at the top of the controller:
329-
330-
.. code-block:: php
329+
IP addresses via the following code at the top of the controller::
331330

332331
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
333332
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
@@ -361,17 +360,20 @@ the directory of the environment you're using (most commonly ``dev`` while
361360
developing and debugging). While it can vary, the ``app/cache/dev`` directory
362361
includes the following:
363362

364-
* ``appDevDebugProjectContainer.php`` - the cached "service container" that
365-
represents the cached application configuration;
363+
``appDevDebugProjectContainer.php``
364+
The cached "service container" that represents the cached application
365+
configuration.
366366

367-
* ``appDevUrlGenerator.php`` - the PHP class generated from the routing
368-
configuration and used when generating URLs;
367+
``appDevUrlGenerator.php``
368+
The PHP class generated from the routing configuration and used when
369+
generating URLs.
369370

370-
* ``appDevUrlMatcher.php`` - the PHP class used for route matching - look
371-
here to see the compiled regular expression logic used to match incoming
372-
URLs to different routes;
371+
``appDevUrlMatcher.php``
372+
The PHP class used for route matching - look here to see the compiled regular
373+
expression logic used to match incoming URLs to different routes.
373374

374-
* ``twig/`` - this directory contains all the cached Twig templates.
375+
``twig/``
376+
This directory contains all the cached Twig templates.
375377

376378
.. note::
377379

cookbook/configuration/front_controllers_and_kernel.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ There are two methods declared in the
9494
left unimplemented in :class:`Symfony\\Component\\HttpKernel\\Kernel`
9595
and thus serve as `template methods`_:
9696

97-
* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles`,
98-
which must return an array of all bundles needed to run the
99-
application;
100-
101-
* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration`,
102-
which loads the application configuration.
97+
:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles`
98+
It must return an array of all bundles needed to run the application.
99+
:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration`
100+
It loads the application configuration.
103101

104102
To fill these (small) blanks, your application needs to subclass the
105103
Kernel and implement these methods. The resulting class is conventionally
@@ -124,8 +122,7 @@ controller to make use of the new kernel.
124122
it might therefore make sense to add additional sub-directories,
125123
for example ``app/admin/AdminKernel.php`` and
126124
``app/api/ApiKernel.php``. All that matters is that your front
127-
controller is able to create an instance of the appropriate
128-
kernel.
125+
controller is able to create an instance of the appropriate kernel.
129126

130127
Having different ``AppKernels`` might be useful to enable different front
131128
controllers (on potentially different servers) to run parts of your application

0 commit comments

Comments
 (0)