From 3bd4e60757200090d7e6f042752fe10318967661 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 10 Sep 2023 19:55:52 +0200 Subject: [PATCH] [TwigBridge] Remove duck typing from AppVariable::getFlashes() --- src/Symfony/Bridge/Twig/AppVariable.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index bc3f611af3739..9d5891240528a 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -152,16 +153,12 @@ public function getLocale(): string public function getFlashes(string|array $types = null): array { try { - if (null === $session = $this->getSession()) { - return []; - } + $session = $this->getSession(); } catch (\RuntimeException) { return []; } - // In 7.0 (when symfony/http-foundation: 6.4 is required) this can be updated to - // check if the session is an instance of FlashBagAwareSessionInterface - if (!method_exists($session, 'getFlashBag')) { + if (!$session instanceof FlashBagAwareSessionInterface) { return []; }