23
23
use Symfony \Component \HttpFoundation \RedirectResponse ;
24
24
use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
25
25
use Symfony \Component \HttpFoundation \Session \Session ;
26
+ use Symfony \Component \HttpFoundation \Session \SessionInterface ;
26
27
use Symfony \Component \HttpFoundation \StreamedResponse ;
27
28
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
28
29
use Symfony \Component \HttpKernel \HttpKernelInterface ;
@@ -76,12 +77,9 @@ protected function getSerializer(): SerializerInterface
76
77
}
77
78
78
79
/**
79
- * An instance of the Session implementation (and not the interface) is returned because getFlashBag is not part of
80
- * the interface.
81
- *
82
80
* @required
83
81
*/
84
- protected function getSession (): Session
82
+ protected function getSession (): SessionInterface
85
83
{
86
84
}
87
85
@@ -235,7 +233,11 @@ protected function file($file, string $fileName = null, string $disposition = Re
235
233
*/
236
234
protected function addFlash (string $ type , string $ message )
237
235
{
238
- $ this ->getSession ()->getFlashBag ()->add ($ type , $ message );
236
+ $ session = $ this ->getSession ();
237
+ if (!$ session instanceof Session) {
238
+ throw new \LogicException (sprintf ('You can not use the addFlash method: "%s" is not an instance of "%s". ' , get_class ($ session ), Session::class));
239
+ }
240
+ $ session ->getFlashBag ()->add ($ type , $ message );
239
241
}
240
242
241
243
/**
@@ -245,8 +247,6 @@ protected function addFlash(string $type, string $message)
245
247
* @param mixed $object The object
246
248
*
247
249
* @return bool
248
- *
249
- * @throws \LogicException
250
250
*/
251
251
protected function isGranted ($ attributes , $ object = null ): bool
252
252
{
@@ -396,8 +396,6 @@ protected function createFormBuilder($data = null, array $options = array()): Fo
396
396
*
397
397
* @return mixed
398
398
*
399
- * @throws \LogicException If SecurityBundle is not available
400
- *
401
399
* @see TokenInterface::getUser()
402
400
*/
403
401
protected function getUser ()
0 commit comments