diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 91c5409a1b..e3784dafd5 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -518,6 +518,30 @@ class Application extends SilexApplication ); } + /** + * Adds a flash message for type. + * + * @param string $type + * @param string $message + */ + public function addFlash($type, $message) + { + return $this['session']->getFlashBag()->add($type, $message); + } + + /** + * Gets and clears flash from the stack. + * + * @param string $type + * @param array $default Default value if $type does not exist. + * + * @return array + */ + public function getFlash($type, array $default = array()) + { + return $this['session']->getFlashBag()->get($type, $default); + } + /** * Tell if current a session is open * diff --git a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php index 7000f4bfe9..5ea8586cba 100644 --- a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php +++ b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php @@ -228,6 +228,17 @@ class ApplicationTest extends \PhraseanetPHPUnitAbstract $this->assertEquals($ret, $app->url($route)); } + public function addSetFlash() + { + $app = new Application('test'); + + $this->assertEquals(array(), $app->getFlash('hello')); + $this->assertEquals('BOUM', $app->getFlash('hello', 'BOUM')); + + $app->setFlash('notice', 'BAMBA'); + $this->assertEquals(array('BAMBA'), $app->getFlash('notice')); + } + private function getAppThatReturnLocale() { $app = new Application('test');