8000 bug #50794 [TwigBridge] Change return type of Symfony\Bridge\Twig\App… · symfony/symfony@7a2b5f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a2b5f2

Browse files
committed
bug #50794 [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession() (Dirkhuethorst)
This PR was submitted for the 6.2 branch but it was squashed and merged into the 6.3 branch instead. Discussion ---------- [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession() Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface', to be in line with the return type of getSession in http-foundation/Request.php | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #50789 | License | MIT | Doc PR | Commits ------- 9dafdc1 [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession()
2 parents b857ae4 + 9dafdc1 commit 7a2b5f2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\RequestStack;
16-
use Symfony\Component\HttpFoundation\Session\Session;
16+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1919
use Symfony\Component\Security\Core\User\UserInterface;
@@ -112,7 +112,7 @@ public function getRequest(): ?Request
112112
/**
113113
* Returns the current session.
114114
*/
115-
public function getSession(): ?Session
115+
public function getSession(): ?SessionInterface
116116
{
117117
if (!isset($this->requestStack)) {
118118
throw new \RuntimeException('The "app.session" variable is not available.');
@@ -171,6 +171,12 @@ public function getFlashes(string|array $types = null): array
171171
return [];
172172
}
173173

174+
// In 7.0 (when symfony/http-foundation: 6.4 is required) this can be updated to
175+
// check if the session is an instance of FlashBagAwareSessionInterface
176+
if (!method_exists($session, 'getFlashBag')) {
177+
return [];
178+
}
179+
174180
if (null === $types || '' === $types || [] === $types) {
175181
return $session->getFlashBag()->all();
176182
}

0 commit comments

Comments
 (0)
0