Skip to content

Commit

Permalink
[TwigBridge] Remove duck typing from AppVariable::getFlashes()
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Sep 10, 2023
1 parent ba0a723 commit 3bd4e60
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Symfony/Bridge/Twig/AppVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [];
}

Expand Down

0 comments on commit 3bd4e60

Please sign in to comment.