[TwigBridge] Make AppVariable check if security.context exists
If security isn't configured in the application, the `security.context` service, nor the `security.token_storage` service exists. Therefore, if a third-party bundle relies on the app.user check in Twig templates, an exception was thrown about asking for an non-existing service. Instead, this change check if the `security.context` actually exists before trying to use it, and return null otherwise.
This commit is contained in:
parent
7493c2bef5
commit
ea71174fb7
@ -74,8 +74,10 @@ class AppVariable
|
||||
throw new \RuntimeException('The "app.security" variable is not available.');
|
||||
}
|
||||
|
||||
if ($this->container->has('security.context')) {
|
||||
return $this->container->get('security.context');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current user.
|
||||
@ -89,6 +91,8 @@ class AppVariable
|
||||
if (null === $this->tokenStorage) {
|
||||
if (null === $this->container) {
|
||||
throw new \RuntimeException('The "app.user" variable is not available.');
|
||||
} elseif (!$this->container->has('security.context')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->tokenStorage = $this->container->get('security.context');
|
||||
|
Reference in New Issue
Block a user