-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 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
84c2e3c
b0466e8
910b5c7
5ae76f1
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 |
---|---|---|
|
@@ -75,7 +75,15 @@ public function initialize(array &$flashes) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function peek($type, $default = null) | ||
public function add($type, $message) | ||
{ | ||
$this->flashes['new'][$type][] = $message; | ||
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. 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. 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. 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, $default = null) | ||
public function get($type, array $default = array()) | ||
{ | ||
$return = $default; | ||
|
||
|
@@ -129,17 +137,17 @@ public function setAll(array $messages) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set($type, $message) | ||
public function set($type, $messages) | ||
{ | ||
$this->flashes['new'][$type] = $message; | ||
$this->flashes['new'][$type] = (array)$messages; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($type) | ||
{ | ||
return array_key_exists($type, $this->flashes['display']); | ||
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(); | ||
$this->flashes = array('display' => array(), 'new' => array()); | ||
|
||
return $return; | ||
return $this->all(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,16 @@ public function getFlashBag() | |
*/ | ||
public function getFlashes() | ||
{ | ||
return $this->getBag('flashes')->all(); | ||
$all = $this->getBag($this->flashName)->all(); | ||
|
||
$return = array(); | ||
if ($all) { | ||
foreach ($all as $name => $array) { | ||
$return[$name] = reset($array); | ||
} | ||
} | ||
|
||
return $return; | ||
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.
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) | ||
{ | ||
$this->getBag('flashes')->setAll($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('flashes')->get($name, $default); | ||
$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('flashes')->set($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('flashes')->has($name); | ||
return $this->getBag($this->flashName)->has($name); | ||
} | ||
|
||
/** | ||
|
@@ -285,7 +298,7 @@ public function hasFlash($name) | |
*/ | ||
public function removeFlash($name) | ||
{ | ||
$this->getBag('flashes')->get($name); | ||
$this->getBag($this->flashName)->get($name); | ||
} | ||
|
||
/** | ||
|
@@ -295,6 +308,6 @@ public function removeFlash($name) | |
*/ | ||
public function clearFlashes() | ||
{ | ||
return $this->getBag('flashes')->clear(); | ||
return $this->getBag($this->flashName)->clear(); | ||
} | ||
} |
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.
You should keep it like it was as you need to keep how it was done in Symfony 2.0, not before your patch.