minor #13512 [TwigBridge] fixed AppVariable compat with older Symfony versions (fabpot)
This PR was merged into the 2.7 branch.
Discussion
----------
[TwigBridge] fixed AppVariable compat with older Symfony versions
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Commits
-------
b0d041f
[TwigBridge] fixed AppVariable compat with older Symfony versions
This commit is contained in:
commit
62decf0bf7
@ -74,7 +74,7 @@ class AppVariable
|
|||||||
throw new \RuntimeException('The "app.security" variable is not available.');
|
throw new \RuntimeException('The "app.security" variable is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->container->get('security');
|
return $this->container->get('security.context');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,9 +87,13 @@ class AppVariable
|
|||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
if (null === $this->tokenStorage) {
|
if (null === $this->tokenStorage) {
|
||||||
|
if (null === $this->container) {
|
||||||
throw new \RuntimeException('The "app.user" variable is not available.');
|
throw new \RuntimeException('The "app.user" variable is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->tokenStorage = $this->container->get('security.context');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$token = $this->tokenStorage->getToken()) {
|
if (!$token = $this->tokenStorage->getToken()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -108,9 +112,13 @@ class AppVariable
|
|||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
if (null === $this->requestStack) {
|
if (null === $this->requestStack) {
|
||||||
|
if (null === $this->container) {
|
||||||
throw new \RuntimeException('The "app.request" variable is not available.');
|
throw new \RuntimeException('The "app.request" variable is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->requestStack = $this->container->get('request_stack');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->requestStack->getCurrentRequest();
|
return $this->requestStack->getCurrentRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +129,6 @@ class AppVariable
|
|||||||
*/
|
*/
|
||||||
public function getSession()
|
public function getSession()
|
||||||
{
|
{
|
||||||
if (null === $this->requestStack) {
|
|
||||||
throw new \RuntimeException('The "app.session" variable is not available.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request = $this->getRequest()) {
|
if ($request = $this->getRequest()) {
|
||||||
return $request->getSession();
|
return $request->getSession();
|
||||||
}
|
}
|
||||||
@ -138,9 +142,13 @@ class AppVariable
|
|||||||
public function getEnvironment()
|
public function getEnvironment()
|
||||||
{
|
{
|
||||||
if (null === $this->environment) {
|
if (null === $this->environment) {
|
||||||
|
if (null === $this->container) {
|
||||||
throw new \RuntimeException('The "app.environment" variable is not available.');
|
throw new \RuntimeException('The "app.environment" variable is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->environment = $this->container->getParameter('kernel.environment');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->environment;
|
return $this->environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,9 +160,13 @@ class AppVariable
|
|||||||
public function getDebug()
|
public function getDebug()
|
||||||
{
|
{
|
||||||
if (null === $this->debug) {
|
if (null === $this->debug) {
|
||||||
|
if (null === $this->container) {
|
||||||
throw new \RuntimeException('The "app.debug" variable is not available.');
|
throw new \RuntimeException('The "app.debug" variable is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->debug = $this->container->getParameter('kernel.debug');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->debug;
|
return $this->debug;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user