-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.1][HttpFoundation] Refactor session handling and flash messages #2853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39288bc
c969423
3a263dc
57ef984
85b5c43
e185c8d
669bc96
7aaf024
1ed6ee3
9dd4dbe
f98f9ae
398acc9
f9951a3
d64939a
4683915
27530cb
5b7ef11
dad60ef
0d2745f
7878a0a
0494250
91f4f8a
74ccf70
93d81a1
146a502
0f6c50a
282d3ae
8a01dd5
b8df162
c59d880
cb6fdb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
UPGRADE FROM 2.0 to 2.1 | ||
======================= | ||
|
||
### General | ||
|
||
* assets_base_urls and base_urls merging strategy has changed | ||
|
||
Unlike most configuration blocks, successive values for | ||
|
@@ -11,6 +13,8 @@ UPGRADE FROM 2.0 to 2.1 | |
and/or share a common base configuration (i.e. ``config.yml``), merging | ||
could yield a set of base URL's for multiple environments. | ||
|
||
### [HttpFoundation] | ||
|
||
* moved management of the locale from the Session class to the Request class | ||
|
||
Configuring the default locale: | ||
|
@@ -28,17 +32,20 @@ UPGRADE FROM 2.0 to 2.1 | |
|
||
Retrieving the locale from a Twig template: | ||
|
||
Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}` | ||
Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}` | ||
|
||
After: `{{ app.request.locale }}` | ||
|
||
Retrieving the locale from a PHP template: | ||
|
||
Before: `$view['session']->getLocale()` | ||
Before: `$view['session']->getLocale()` | ||
|
||
After: `$view['request']->getLocale()` | ||
|
||
Retrieving the locale from PHP code: | ||
|
||
Before: `$session->getLocale()` | ||
Before: `$session->getLocale()` | ||
|
||
After: `$request->getLocale()` | ||
|
||
* Method `equals` of `Symfony\Component\Security\Core\User\UserInterface` has | ||
|
@@ -134,7 +141,7 @@ UPGRADE FROM 2.0 to 2.1 | |
|
||
* The strategy for generating the HTML attributes "id" and "name" | ||
of choices in a choice field has changed | ||
|
||
Instead of appending the choice value, a generated integer is now appended | ||
by default. Take care if your Javascript relies on that. If you can | ||
guarantee that your choice values only contain ASCII letters, digits, | ||
|
@@ -144,7 +151,7 @@ UPGRADE FROM 2.0 to 2.1 | |
|
||
* The strategy for generating the HTML attributes "value" of choices in a | ||
choice field has changed | ||
|
||
Instead of using the choice value, a generated integer is now stored. | ||
Again, take care if your Javascript reads this value. If your choice field | ||
is a non-expanded single-choice field, or if the choices are guaranteed not | ||
|
@@ -248,3 +255,63 @@ UPGRADE FROM 2.0 to 2.1 | |
{ | ||
return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice'; | ||
} | ||
|
||
* Flash Messages now returns and array based on type (the old method are still available but deprecated) | ||
|
||
Before (PHP): | ||
|
||
<?php if ($view['session']->hasFlash('notice')): ?> | ||
<div class="flash-notice"> | ||
<?php echo $view['session']->getFlash('notice') ?> | ||
</div> | ||
<?php endif; ?> | ||
|
||
After (PHP): | ||
|
||
<?php if ($view['session']->getFlashBag()->has('notice')): ?> | ||
<div class="flash-notice"> | ||
<?php echo $view['session']->getFlashBag()->get('notice') ?> | ||
</div> | ||
<?php endif; ?> | ||
|
||
If you wanted to process all flash types you could also make use of the `getFlashBag()->all()` API: | ||
|
||
<?php foreach ($view['session']->getFlashBag()->all() as $type => $flash): ?> | ||
<div class="flash-$type"> | ||
<?php echo $flash; ?> | ||
</div> | ||
<?php endforeach; ?> | ||
|
||
Before (Twig): | ||
|
||
{% if app.session.hasFlash('notice') %} | ||
<div class="flash-notice"> | ||
{{ app.session.flash('notice') }} | ||
</div> | ||
{% endif %} | ||
|
||
After (Twig): | ||
|
||
{% if app.session.flashes.has('notice') %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fabpot shouldn't it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
<div class="flash-notice"> | ||
{{ app.session.flashes.get('notice') }} | ||
</div> | ||
{% endif %} | ||
|
||
Again you can process all flash messages in one go with | ||
|
||
{% for type, flashMessage in app.session.flashes.all() %} | ||
<div class="flash-{{ type }}"> | ||
{{ flashMessage }} | ||
</div> | ||
{% endforeach %} | ||
|
||
* Session storage drivers | ||
|
||
Session storage drivers should inherit from | ||
`Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage` | ||
and no longer should implement `read()`, `write()`, `remove()` which were removed from the | ||
`SessionStorageInterface`. | ||
|
||
Any session storage driver that wants to use custom save handlers should | ||
implement `Symfony\Component\HttpFoundation\Session\Storage\SaveHandlerInterface` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,7 +301,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c | |
|
||
$this->addClassesToCompile(array( | ||
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener', | ||
'Symfony\\Component\\HttpFoundation\\SessionStorage\\SessionStorageInterface', | ||
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't you add the abstract storage too ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. thanks. |
||
$container->getDefinition('session')->getClass(), | ||
)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong.
$view['session']
is not the Session object in the PHP templates but the SessionHelper which is BC.The Session object is available through
$app->getSession()
(equivalent to the Twig way to access it)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed