Skip to content

Commit d981337

Browse files
committed
Merge remote-tracking branch 'origin/2.1' into 2.1
2 parents 3ce0098 + d248033 commit d981337

File tree

5 files changed

+100
-70
lines changed

5 files changed

+100
-70
lines changed

book/controller.rst

+10-14
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,19 @@ the ``notice`` message:
686686

687687
.. code-block:: html+jinja
688688

689-
{% if app.session.started %}
690-
{% for flashMessage in app.session.flashbag.get('notice') %}
691-
<div class="flash-notice">
692-
{{ flashMessage }}
693-
</div>
694-
{% endfor %}
695-
{% endif %}
689+
{% for flashMessage in app.session.flashbag.get('notice') %}
690+
<div class="flash-notice">
691+
{{ flashMessage }}
692+
</div>
693+
{% endfor %}
696694

697695
.. code-block:: html+php
698696

699-
<?php if ($view['session']->isStarted()): ?>
700-
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
701-
<div class="flash-notice">
702-
<?php echo "<div class='flash-error'>$message</div>" ?>
703-
</div>
704-
<?php endforeach; ?>
705-
<?php endif; ?>
697+
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
698+
<div class="flash-notice">
699+
<?php echo "<div class='flash-error'>$message</div>" ?>
700+
</div>
701+
<?php endforeach; ?>
706702

707703
By design, flash messages are meant to live for exactly one request (they're
708704
"gone in a flash"). They're designed to be used across redirects exactly as

book/templating.rst

+1-35
Original file line numberDiff line numberDiff line change
@@ -1340,43 +1340,9 @@ in a JavaScript string, use the ``js`` context:
13401340
Debugging
13411341
---------
13421342

1343-
.. versionadded:: 2.0.9
1344-
This feature is available as of Twig ``1.5.x``, which was first shipped
1345-
with Symfony 2.0.9.
1346-
13471343
When using PHP, you can use ``var_dump()`` if you need to quickly find the
13481344
value of a variable passed. This is useful, for example, inside your controller.
1349-
The same can be achieved when using Twig by using the debug extension. This
1350-
needs to be enabled in the config:
1351-
1352-
.. configuration-block::
1353-
1354-
.. code-block:: yaml
1355-
1356-
# app/config/config.yml
1357-
services:
1358-
acme_hello.twig.extension.debug:
1359-
class: Twig_Extension_Debug
1360-
tags:
1361-
- { name: 'twig.extension' }
1362-
1363-
.. code-block:: xml
1364-
1365-
<!-- app/config/config.xml -->
1366-
<services>
1367-
<service id="acme_hello.twig.extension.debug" class="Twig_Extension_Debug">
1368-
<tag name="twig.extension" />
1369-
</service>
1370-
</services>
1371-
1372-
.. code-block:: php
1373-
1374-
// app/config/config.php
1375-
use Symfony\Component\DependencyInjection\Definition;
1376-
1377-
$definition = new Definition('Twig_Extension_Debug');
1378-
$definition->addTag('twig.extension');
1379-
$container->setDefinition('acme_hello.twig.extension.debug', $definition);
1345+
The same can be achieved when using Twig thanks to the the debug extension.
13801346

13811347
Template parameters can then be dumped using the ``dump`` function:
13821348

components/http_foundation/sessions.rst

-13
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,3 @@ Compact method to process display all flashes at once::
333333
echo "<div class='flash-$type'>$message</div>\n";
334334
}
335335
}
336-
337-
.. caution::
338-
339-
As flash messages use a session to store the messages from one request to
340-
the next one, a session will be automatically started when you read the
341-
flash messages even if none already exists. To avoid that default
342-
behavior, test if there is an existing session first::
343-
344-
if ($session->isStarted()) {
345-
foreach ($session->getFlashBag()->get('warning', array()) as $message) {
346-
echo "<div class='flash-warning'>$message</div>";
347-
}
348-
}

cookbook/cache/varnish.rst

+86-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ application:
3535
.. code-block:: text
3636
3737
sub vcl_recv {
38+
// Add a Surrogate-Capability header to announce ESI support.
3839
set req.http.Surrogate-Capability = "abc=ESI/1.0";
3940
}
4041
@@ -45,12 +46,16 @@ Symfony2 adds automatically:
4546
.. code-block:: text
4647
4748
sub vcl_fetch {
49+
/*
50+
Check for ESI acknowledgement
51+
and remove Surrogate-Control header
52+
*/
4853
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
4954
unset beresp.http.Surrogate-Control;
5055
51-
// for Varnish >= 3.0
56+
// For Varnish >= 3.0
5257
set beresp.do_esi = true;
53-
// for Varnish < 3.0
58+
// For Varnish < 3.0
5459
// esi;
5560
}
5661
}
@@ -75,14 +80,43 @@ that will invalidate the cache for a given resource:
7580

7681
.. code-block:: text
7782
83+
/*
84+
Connect to the backend server
85+
on the local machine on port 8080
86+
*/
87+
backend default {
88+
.host = "127.0.0.1";
89+
.port = "8080";
90+
}
91+
92+
sub vcl_recv {
93+
/*
94+
Varnish default behaviour doesn't support PURGE.
95+
Match the PURGE request and immediately do a cache lookup,
96+
otherwise Varnish will directly pipe the request to the backend
97+
and bypass the cache
98+
*/
99+
if (req.request == "PURGE") {
100+
return(lookup);
101+
}
102+
}
103+
78104
sub vcl_hit {
105+
// Match PURGE request
79106
if (req.request == "PURGE") {
107+
// Force object expiration for Varnish < 3.0
80108
set obj.ttl = 0s;
109+
// Do an actual purge for Varnish >= 3.0
110+
// purge;
81111
error 200 "Purged";
82112
}
83113
}
84114
85115
sub vcl_miss {
116+
/*
117+
Match the PURGE request and
118+
indicate the request wasn't stored in cache.
119+
*/
86120
if (req.request == "PURGE") {
87121
error 404 "Not purged";
88122
}
@@ -91,7 +125,56 @@ that will invalidate the cache for a given resource:
91125
.. caution::
92126

93127
You must protect the ``PURGE`` HTTP method somehow to avoid random people
94-
purging your cached data.
128+
purging your cached data. You can do this by setting up an access list:
129+
130+
.. code-block:: text
131+
/*
132+
Connect to the backend server
133+
on the local machine on port 8080
134+
*/
135+
backend default {
136+
.host = "127.0.0.1";
137+
.port = "8080";
138+
}
139+
140+
// Acl's can contain IP's, subnets and hostnames
141+
acl purge {
142+
"localhost";
143+
"192.168.55.0"/24;
144+
}
145+
146+
sub vcl_recv {
147+
// Match PURGE request to avoid cache bypassing
148+
if (req.request == "PURGE") {
149+
// Match client IP to the acl
150+
if (!client.ip ~ purge) {
151+
// Deny access
152+
error 405 "Not allowed.";
153+
}
154+
// Perform a cache lookup
155+
return(lookup);
156+
}
157+
}
158+
159+
sub vcl_hit {
160+
// Match PURGE request
161+
if (req.request == "PURGE") {
162+
// Force object expiration for Varnish < 3.0
163+
set obj.ttl = 0s;
164+
// Do an actual purge for Varnish >= 3.0
165+
// purge;
166+
error 200 "Purged";
167+
}
168+
}
169+
170+
sub vcl_miss {
171+
// Match PURGE request
172+
if (req.request == "PURGE") {
173+
// Indicate that the object isn't stored in cache
174+
error 404 "Not purged";
175+
}
176+
}
177+
95178
96179
.. _`Edge Architecture`: http://www.w3.org/TR/edge-arch
97180
.. _`GZIP and Varnish`: https://www.varnish-cache.org/docs/3.0/phk/gzip.html

quick_tour/the_controller.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ next request::
141141

142142
// display any messages back in the next request (in a template)
143143

144-
{% if app.session.started %}
145-
{% for flashMessage in app.session.flashbag.get('notice') %}
146-
<div>{{ flashMessage }}</div>
147-
{% endfor %}
148-
{% endif %}
144+
{% for flashMessage in app.session.flashbag.get('notice') %}
145+
<div>{{ flashMessage }}</div>
146+
{% endfor %}
149147

150148
This is useful when you need to set a success message before redirecting
151149
the user to another page (which will then show the message). Please note that

0 commit comments

Comments
 (0)