[TwigBundle] fall back to security instead of tokenStorage when not available

This commit is contained in:
Fabien Potencier 2015-01-13 07:56:56 +01:00
parent c7ae71d6da
commit b529830d6f

View File

@ -86,11 +86,15 @@ class AppVariable
*/ */
public function getUser() 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.'); throw new \RuntimeException('The "app.user" variable is not available.');
} }
if (!$token = $this->tokenStorage->getToken()) { if (!$token = $tokenStorage->getToken()) {
return; return;
} }