2323use Symfony \Component \HttpFoundation \RedirectResponse ;
2424use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
2525use Symfony \Component \HttpFoundation \Session \Session ;
26+ use Symfony \Component \HttpFoundation \Session \SessionInterface ;
2627use Symfony \Component \HttpFoundation \StreamedResponse ;
2728use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
2829use Symfony \Component \HttpKernel \HttpKernelInterface ;
@@ -76,12 +77,9 @@ protected function getSerializer(): SerializerInterface
7677 }
7778
7879 /**
79- * An instance of the Session implementation (and not the interface) is returned because getFlashBag is not part of
80- * the interface.
81- *
8280 * @required
8381 */
84- protected function getSession (): Session
82+ protected function getSession (): SessionInterface
8583 {
8684 }
8785
@@ -235,7 +233,11 @@ protected function file($file, string $fileName = null, string $disposition = Re
235233 */
236234 protected function addFlash (string $ type , string $ message )
237235 {
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 );
239241 }
240242
241243 /**
@@ -245,8 +247,6 @@ protected function addFlash(string $type, string $message)
245247 * @param mixed $object The object
246248 *
247249 * @return bool
248- *
249- * @throws \LogicException
250250 */
251251 protected function isGranted ($ attributes , $ object = null ): bool
252252 {
@@ -396,8 +396,6 @@ protected function createFormBuilder($data = null, array $options = array()): Fo
396396 *
397397 * @return mixed
398398 *
399- * @throws \LogicException If SecurityBundle is not available
400- *
401399 * @see TokenInterface::getUser()
402400 */
403401 protected function getUser ()
0 commit comments