Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c1e99e

Browse files
committed
cleanup flash message listener naming and doc
1 parent cd086fd commit 0c1e99e

8 files changed

Lines changed: 32 additions & 37 deletions

File tree

DependencyInjection/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getConfigTreeBuilder()
9999
$this->addTagSection($rootNode);
100100
$this->addInvalidationSection($rootNode);
101101
$this->addUserContextListenerSection($rootNode);
102-
$this->addFlashMessageListenerSection($rootNode);
102+
$this->addFlashMessageSection($rootNode);
103103
$this->addDebugSection($rootNode);
104104

105105
return $treeBuilder;
@@ -417,11 +417,11 @@ private function addUserContextListenerSection(ArrayNodeDefinition $rootNode)
417417
;
418418
}
419419

420-
private function addFlashMessageListenerSection(ArrayNodeDefinition $rootNode)
420+
private function addFlashMessageSection(ArrayNodeDefinition $rootNode)
421421
{
422422
$rootNode
423423
->children()
424-
->arrayNode('flash_message_listener')
424+
->arrayNode('flash_message')
425425
->canBeUnset()
426426
->canBeEnabled()
427427
->info('Activate the flash message listener that puts flash messages into a cookie.')

DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@
2626
*/
2727
class FOSHttpCacheExtension extends Extension
2828
{
29+
/**
30+
* {@inheritDoc}
31+
*/
32+
public function getConfiguration(array $config, ContainerBuilder $container)
33+
{
34+
return new Configuration($container->getParameter('kernel.debug'));
35+
}
36+
2937
/**
3038
* {@inheritDoc}
3139
*/
3240
public function load(array $configs, ContainerBuilder $container)
3341
{
34-
$configuration = new Configuration($container->getParameter('kernel.debug'));
42+
$configuration = $this->getConfiguration($configs, $container);
3543
$config = $this->processConfiguration($configuration, $configs);
3644

3745
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -85,10 +93,10 @@ public function load(array $configs, ContainerBuilder $container)
8593
$this->loadUserContext($container, $loader, $config['user_context']);
8694
}
8795

88-
if (!empty($config['flash_message_listener']) && $config['flash_message_listener']['enabled']) {
89-
$container->setParameter($this->getAlias().'.event_listener.flash_message.options', $config['flash_message_listener']);
96+
if (!empty($config['flash_message']) && $config['flash_message']['enabled']) {
97+
$container->setParameter($this->getAlias().'.event_listener.flash_message.options', $config['flash_message']);
9098

91-
$loader->load('flash_message_listener.xml');
99+
$loader->load('flash_message.xml');
92100
}
93101
}
94102

File renamed without changes.

Resources/doc/event-subscribers/flash-message.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ Flash Message Subscriber
22
========================
33

44
When flash messages are rendered into the content of a page, you can't cache
5-
the page anymore. This listener reads all flash messages into a cookie, leading
6-
to them not being there anymore when rendering the template. This will return
7-
the page with a set-cookie header which you of course must make sure to not
8-
cache in varnish. By default, varnish will simply not cache the whole response
9-
when there is a set-cookie header. (Maybe you could do something more clever -
10-
if you do, please provide a VCL example.)
5+
the page anymore. When enabled, this subscriber reads all flash messages into a
6+
cookie, leading to them not being there anymore when rendering the template.
7+
This will return the page with a set-cookie header which you of course must
8+
make sure to not cache in varnish. By default, varnish will simply not cache
9+
the whole response when there is a set-cookie header. (Maybe you could do
10+
something more clever - if you do, please provide a VCL example.)
11+
12+
The flash message subscriber is automatically enabled if you configure any of
13+
the options under ``flash_message``.
1114

1215
.. code-block:: yaml
1316
1417
# app/config.yml
1518
fos_http_cache:
16-
flash_message_listener:
19+
flash_message:
1720
name: flashes
1821
path: /
1922
host: null
@@ -42,7 +45,7 @@ show the flash message once. This could look along these lines:
4245
4346
function showFlash()
4447
{
45-
var cookie = getCookie("flashes"); // fos_http_cache.flash_message_listener.name
48+
var cookie = getCookie("flashes"); // fos_http_cache.flash_message.name
4649
4750
if (!cookie) {
4851
return;

Tests/Resources/Fixtures/config/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
'user_hash_header' => 'FOS-User-Context-Hash',
8686
'role_provider' => true,
8787
),
88-
'flash_message_listener' => array(
88+
'flash_message' => array(
8989
'enabled' => true,
9090
'name' => 'flashtest',
9191
'path' => '/x',

Tests/Resources/Fixtures/config/full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fos_http_cache:
8080
- Authorization
8181
user_hash_header: FOS-User-Context-Hash
8282

83-
flash_message_listener:
83+
flash_message:
8484
name: flashtest
8585
path: /x
8686
host: y

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testSupportsAllConfigFormats()
138138
'user_hash_header' => 'FOS-User-Context-Hash',
139139
'role_provider' => true,
140140
),
141-
'flash_message_listener' => array(
141+
'flash_message' => array(
142142
'enabled' => true,
143143
'name' => 'flashtest',
144144
'path' => '/x',
@@ -367,7 +367,7 @@ private function getEmptyConfig()
367367
'user_hash_header' => 'X-User-Context-Hash',
368368
'role_provider' => false,
369369
),
370-
'flash_message_listener' => array(
370+
'flash_message' => array(
371371
'enabled' => false,
372372
'name' => 'flashes',
373373
'path' => '/',

Tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,26 +240,10 @@ public function testConfigWithoutUserContext()
240240
$this->assertFalse($container->has('fos_http_cache.user_context.role_provider'));
241241
}
242242

243-
public function testConfigLoadFlashMessageListener()
243+
public function testConfigLoadFlashMessageSubscriber()
244244
{
245245
$config = array(
246-
array('flash_message_listener' => array(
247-
'name' => 'myflashes',
248-
'path' => '/test',
249-
'host' => '*.fos.lo',
250-
'secure' => true,
251-
'httpOnly' => false,
252-
)),
253-
);
254-
255-
$container = $this->createContainer();
256-
$this->extension->load($config, $container);
257-
}
258-
259-
public function testConfigLoadFlashMessageListenerDefaults()
260-
{
261-
$config = array(
262-
array('flash_message_listener' => true,
246+
array('flash_message' => true,
263247
),
264248
);
265249

0 commit comments

Comments
 (0)