From b529830d6f637249028e8958abe0833a4bda710d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 13 Jan 2015 07:56:56 +0100 Subject: [PATCH] [TwigBundle] fall back to security instead of tokenStorage when not available --- src/Symfony/Bundle/TwigBundle/AppVariable.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/AppVariable.php b/src/Symfony/Bundle/TwigBundle/AppVariable.php index f40cba5cd1..7cbaf4342e 100644 --- a/src/Symfony/Bundle/TwigBundle/AppVariable.php +++ b/src/Symfony/Bundle/TwigBundle/AppVariable.php @@ -86,11 +86,15 @@ class AppVariable */ public function getUser() { - if (null === $this->tokenStorage) { + if (null !== $this->tokenStorage) { + $tokenStorage = $this->tokenStorage; + } elseif (null !== $this->security) { + $tokenStorage = $this->security; + } else { throw new \RuntimeException('The "app.user" variable is not available.'); } - if (!$token = $this->tokenStorage->getToken()) { + if (!$token = $tokenStorage->getToken()) { return; }