Skip to content

Commit

Permalink
[TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::g…
Browse files Browse the repository at this point in the history
…etSession()
  • Loading branch information
Dirkhuethorst authored and fabpot committed Sep 10, 2023
1 parent b857ae4 commit 9dafdc1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Symfony/Bridge/Twig/AppVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -112,7 +112,7 @@ public function getRequest(): ?Request
/**
* Returns the current session.
*/
public function getSession(): ?Session
public function getSession(): ?SessionInterface
{
if (!isset($this->requestStack)) {
throw new \RuntimeException('The "app.session" variable is not available.');
Expand Down Expand Up @@ -171,6 +171,12 @@ public function getFlashes(string|array $types = null): array
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')) {
return [];
}

if (null === $types || '' === $types || [] === $types) {
return $session->getFlashBag()->all();
}
Expand Down

0 comments on commit 9dafdc1

Please sign in to comment.