[Bridge] [Twig] AppVariable: get and flush only flash sessions you need in getFlashes method

This commit is contained in:
Jordan Samouh 2017-04-10 16:49:57 +02:00
parent bc93526731
commit ff82cb29bb
2 changed files with 13 additions and 1 deletions

View File

@ -174,6 +174,13 @@ class AppVariable
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;
}
}

View File

@ -212,6 +212,11 @@ class AppVariableTest extends TestCase
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)