Skip to content

Commit

Permalink
bug #22359 [Bridge] [Twig] Get and flush only flash sessions you need…
Browse files Browse the repository at this point in the history
… in getFlashes method (jordscream)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Bridge] [Twig] Get and flush only flash sessions you need in getFlashes method

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no ?!
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #22355
| License       | MIT
| Doc PR        | symfony/symfony-docs

PR to get only flash sessions you need without flush everything

Commits
-------

ff82cb2 [Bridge] [Twig] AppVariable: get and flush only flash sessions you need in getFlashes method
  • Loading branch information
fabpot committed Apr 10, 2017
2 parents bc93526 + ff82cb2 commit 3f7a157
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Symfony/Bridge/Twig/AppVariable.php
Expand Up @@ -174,6 +174,13 @@ public function getFlashes($types = null)
return $session->getFlashBag()->get($types);
}

return array_intersect_key($session->getFlashBag()->all(), array_flip($types));
$result = array();
foreach ($types as $type) {
if ($value = $session->getFlashBag()->get($type)) {
$result[$type] = $value;
}
}

return $result;
}
}
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/AppVariableTest.php
Expand Up @@ -212,6 +212,11 @@ public function testGetFlashes()
array('notice' => $flashMessages['notice'], 'error' => $flashMessages['error']),
$this->appVariable->getFlashes(array('notice', 'error'))
);

$this->assertEquals(
array('warning' => $flashMessages['warning']),
$this->appVariable->getFlashes(array('warning'))
);
}

protected function setRequestStack($request)
Expand Down

0 comments on commit 3f7a157

Please sign in to comment.