Skip to content

Commit ddcbd23

Browse files
VincentLangletfabpot
authored andcommitted
Add deprecation when the session is not FlashBagAware
1 parent 725b56c commit ddcbd23

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Controller/AbstractController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\HttpFoundation\RequestStack;
2929
use Symfony\Component\HttpFoundation\Response;
3030
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
31+
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
3132
use Symfony\Component\HttpFoundation\StreamedResponse;
3233
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3334
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -173,10 +174,16 @@ protected function file(\SplFileInfo|string $file, string $fileName = null, stri
173174
protected function addFlash(string $type, mixed $message): void
174175
{
175176
try {
176-
$this->container->get('request_stack')->getSession()->getFlashBag()->add($type, $message);
177+
$session = $this->container->get('request_stack')->getSession();
177178
} catch (SessionNotFoundException $e) {
178179
throw new \LogicException('You cannot use the addFlash method if sessions are disabled. Enable them in "config/packages/framework.yaml".', 0, $e);
179180
}
181+
182+
if (!$session instanceof FlashBagAwareSessionInterface) {
183+
trigger_deprecation('symfony/framework-bundle', '6.2', 'Calling "addFlash()" method when the session does not implement %s is deprecated.', FlashBagAwareSessionInterface::class);
184+
}
185+
186+
$session->getFlashBag()->add($type, $message);
180187
}
181188

182189
/**

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/deprecation-contracts": "^2.1|^3",
2626
"symfony/error-handler": "^6.1",
2727
"symfony/event-dispatcher": "^5.4|^6.0",
28-
"symfony/http-foundation": "^5.4|^6.0",
28+
"symfony/http-foundation": "^6.2",
2929
"symfony/http-kernel": "^6.2",
3030
"symfony/polyfill-mbstring": "~1.0",
3131
"symfony/filesystem": "^5.4|^6.0",

0 commit comments

Comments
 (0)