diff --git a/src/Symfony/Http/Request.php b/src/Symfony/Http/Request.php index cdf6be7e..5b7af350 100644 --- a/src/Symfony/Http/Request.php +++ b/src/Symfony/Http/Request.php @@ -52,6 +52,15 @@ final class Request implements RequestInterface */ public function hasType($type) { + if (!$this->hasSession()) { + return false; + } + + $session = $this->request->getSession(); + if (!$session->isStarted()) { + return false; + } + /** @var Session $session */ $session = $this->request->getSession(); $flashBag = $session->getFlashBag(); diff --git a/src/Symfony/Storage/FallbackSession.php b/src/Symfony/Storage/FallbackSession.php new file mode 100644 index 00000000..96e8482d --- /dev/null +++ b/src/Symfony/Storage/FallbackSession.php @@ -0,0 +1,32 @@ +session = $session; + $this->fallbackSession = new FallbackSession(); } /** @@ -54,10 +61,20 @@ final class SessionBag implements BagInterface return $this->session; // @phpstan-ignore-line } - if (method_exists($this->session, 'getSession')) { - return $this->session = $this->session->getSession(); - } + try { + if (method_exists($this->session, 'getSession')) { + $session = $this->session->getSession(); + } else { + $session = $this->session->getCurrentRequest()->getSession(); + } - return $this->session = $this->session->getCurrentRequest()->getSession(); // @phpstan-ignore-line + if (null !== $session && $session->isStarted()) { + return $this->session = $session; + } + + return $this->fallbackSession; + } catch (SessionNotFoundException $e) { + return $this->fallbackSession; + } } }