Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[2.1][HttpFoundation] Multiple session flash messages#3267
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -307,30 +307,31 @@ UPGRADE FROM 2.0 to 2.1 | ||
| Before: | ||
| ``` | ||
| {% if app.session.flashbag.has('notice') %} | ||
Member 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. You should keep it like it was as you need to keep how it was done in Symfony 2.0, not before your patch. | ||
| <div class="flash-notice"> | ||
| {{ app.session.flashbag.get('notice') }} | ||
| </div> | ||
| {% endif %} | ||
| ``` | ||
| After: | ||
| ``` | ||
| {%for flashMessage inapp.session.flashbag.get('notice') %} | ||
| <div class="flash-notice"> | ||
| {{flashMessage }} | ||
| </div> | ||
| {%endfor %} | ||
| ``` | ||
| You can process all flash messges in a single loop with: | ||
| ``` | ||
| {% for type, flashMessages in app.session.flashbag.all() %} | ||
| {% for flashMessage in flashMessages) %} | ||
| <div class="flash-{{ type }}"> | ||
| {{ flashMessage }} | ||
| </div> | ||
| {% endfor %} | ||
| {% endfor %} | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -75,7 +75,15 @@ public function initialize(array &$flashes) | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function add($type, $message) | ||
| { | ||
| $this->flashes['new'][$type][] = $message; | ||
Contributor 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. Will this generate a notice is flashes['new'][$type] is not yet defined? I seem to recall it doing so for me in the past. Member 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. It doesn't. Contributor 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. Ah good. Just checking. Member 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. reading throw a notice. Writing does not | ||
| } | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function peek($type, array $default = array()) | ||
| { | ||
| return $this->has($type) ? $this->flashes['display'][$type] : $default; | ||
| } | ||
| @@ -91,7 +99,7 @@ public function peekAll() | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function get($type,array$default =array()) | ||
| { | ||
| $return = $default; | ||
| @@ -129,17 +137,17 @@ public function setAll(array $messages) | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function set($type, $messages) | ||
| { | ||
| $this->flashes['new'][$type] =(array)$messages; | ||
| } | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function has($type) | ||
| { | ||
| return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type]; | ||
| } | ||
| /** | ||
| @@ -163,9 +171,6 @@ public function getStorageKey() | ||
| */ | ||
| public function clear() | ||
| { | ||
| return $this->all(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -229,7 +229,16 @@ public function getFlashBag() | ||
| */ | ||
| public function getFlashes() | ||
| { | ||
| $all = $this->getBag($this->flashName)->all(); | ||
| $return = array(); | ||
| if ($all) { | ||
| foreach ($all as $name => $array) { | ||
| $return[$name] = reset($array); | ||
| } | ||
| } | ||
| return $return; | ||
Contributor 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. Can this be simplified? It's not clear why we have to manually build out the return value.
Author 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. No no, this API is designed to replicate the old functionality (no arrays). All this API is already deprecated. | ||
| } | ||
| /** | ||
| @@ -239,7 +248,9 @@ public function getFlashes() | ||
| */ | ||
| public function setFlashes($values) | ||
| { | ||
| foreach ($values as $name => $value) { | ||
| $this->getBag($this->flashName)->set($name, $value); | ||
| } | ||
| } | ||
| /** | ||
| @@ -252,7 +263,9 @@ public function setFlashes($values) | ||
| */ | ||
| public function getFlash($name, $default = null) | ||
| { | ||
| $return = $this->getBag($this->flashName)->get($name); | ||
| return empty($return) ? $default : reset($return); | ||
| } | ||
| /** | ||
| @@ -263,7 +276,7 @@ public function getFlash($name, $default = null) | ||
| */ | ||
| public function setFlash($name, $value) | ||
| { | ||
| $this->getBag($this->flashName)->set($name, $value); | ||
| } | ||
| /** | ||
| @@ -275,7 +288,7 @@ public function setFlash($name, $value) | ||
| */ | ||
| public function hasFlash($name) | ||
| { | ||
| return $this->getBag($this->flashName)->has($name); | ||
| } | ||
| /** | ||
| @@ -285,7 +298,7 @@ public function hasFlash($name) | ||
| */ | ||
| public function removeFlash($name) | ||
| { | ||
| $this->getBag($this->flashName)->get($name); | ||
| } | ||
| /** | ||
| @@ -295,6 +308,6 @@ public function removeFlash($name) | ||
| */ | ||
| public function clearFlashes() | ||
| { | ||
| return $this->getBag($this->flashName)->clear(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.