Skip to content
This repository
Browse code

[HttpFoudation] CS, more tests and some optimization.

  • Loading branch information...
commit 910b5c7f834776f6ac074c0e00b4dfcde39a2b2b 1 parent b0466e8
Drak drak authored
4 src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php
@@ -46,9 +46,9 @@ public function get($name, $default = null)
46 46 return $this->session->get($name, $default);
47 47 }
48 48
49   - public function getFlash($name, $default = null)
  49 + public function getFlash($name, array $default = array())
50 50 {
51   - return $this->session->getFlashBag()->get($name);
  51 + return $this->session->getFlashBag()->get($name, $default);
52 52 }
53 53
54 54 public function getFlashes()
8 src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php
@@ -139,8 +139,7 @@ public function setAll(array $messages)
139 139 */
140 140 public function set($type, $messages)
141 141 {
142   - $messages = (array)$messages;
143   - $this->flashes['new'][$type] = $messages;
  142 + $this->flashes['new'][$type] = (array)$messages;
144 143 }
145 144
146 145 /**
@@ -172,9 +171,6 @@ public function getStorageKey()
172 171 */
173 172 public function clear()
174 173 {
175   - $return = $this->all();
176   - $this->flashes = array('display' => array(), 'new' => array());
177   -
178   - return $return;
  174 + return $this->all();
179 175 }
180 176 }
3  src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php
@@ -121,8 +121,7 @@ public function all()
121 121 */
122 122 public function set($type, $messages)
123 123 {
124   - $messages = (array)$messages;
125   - $this->flashes[$type] = $messages;
  124 + $this->flashes[$type] = (array) $messages;
126 125 }
127 126
128 127 /**
1  src/Symfony/Component/HttpFoundation/Session/Session.php
@@ -310,5 +310,4 @@ public function clearFlashes()
310 310 {
311 311 return $this->getBag($this->flashName)->clear();
312 312 }
313   -
314 313 }
2  tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php
@@ -150,6 +150,6 @@ public function testAll()
150 150
151 151 public function testClear()
152 152 {
153   - $this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear());
  153 + $this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
154 154 }
155 155 }
10 tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php
@@ -175,13 +175,21 @@ public function testGetSetFlashes()
175 175 $this->session->setFlashes($array);
176 176 $this->assertEquals($array, $this->session->getFlashes());
177 177 $this->assertEquals(array(), $this->session->getFlashes());
  178 + $this->session->getFlashBag()->add('notice', 'foo');
  179 +
  180 + // test that BC works by only retrieving the first added.
  181 + $this->session->getFlashBag()->add('notice', 'foo2');
  182 + $this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
178 183 }
179 184
180 185 public function testGetSetFlash()
181 186 {
182 187 $this->assertNull($this->session->getFlash('notice'));
183 188 $this->assertEquals('default', $this->session->getFlash('notice', 'default'));
184   - $this->session->setFlash('notice', 'foo');
  189 + $this->session->getFlashBag()->add('notice', 'foo');
  190 + $this->session->getFlashBag()->add('notice', 'foo2');
  191 +
  192 + // test that BC works by only retrieving the first added.
185 193 $this->assertEquals('foo', $this->session->getFlash('notice'));
186 194 $this->assertNull($this->session->getFlash('notice'));
187 195 }

0 comments on commit 910b5c7

Please sign in to comment.
Something went wrong with that request. Please try again.