Skip to content

Commit

Permalink
[TwigBridge] fixed AppVariable compat with older Symfony versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 25, 2015
1 parent 3d174a4 commit b0d041f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/Symfony/Bridge/Twig/AppVariable.php
Expand Up @@ -74,7 +74,7 @@ public function getSecurity()
throw new \RuntimeException('The "app.security" variable is not available.');
}

return $this->container->get('security');
return $this->container->get('security.context');
}

/**
Expand All @@ -87,7 +87,11 @@ public function getSecurity()
public function getUser()
{
if (null === $this->tokenStorage) {
throw new \RuntimeException('The "app.user" variable is not available.');
if (null === $this->container) {
throw new \RuntimeException('The "app.user" variable is not available.');
}

$this->tokenStorage = $this->container->get('security.context');
}

if (!$token = $this->tokenStorage->getToken()) {
Expand All @@ -108,7 +112,11 @@ public function getUser()
public function getRequest()
{
if (null === $this->requestStack) {
throw new \RuntimeException('The "app.request" variable is not available.');
if (null === $this->container) {
throw new \RuntimeException('The "app.request" variable is not available.');
}

$this->requestStack = $this->container->get('request_stack');
}

return $this->requestStack->getCurrentRequest();
Expand All @@ -121,10 +129,6 @@ public function getRequest()
*/
public function getSession()
{
if (null === $this->requestStack) {
throw new \RuntimeException('The "app.session" variable is not available.');
}

if ($request = $this->getRequest()) {
return $request->getSession();
}
Expand All @@ -138,7 +142,11 @@ public function getSession()
public function getEnvironment()
{
if (null === $this->environment) {
throw new \RuntimeException('The "app.environment" variable is not available.');
if (null === $this->container) {
throw new \RuntimeException('The "app.environment" variable is not available.');
}

$this->environment = $this->container->getParameter('kernel.environment');
}

return $this->environment;
Expand All @@ -152,7 +160,11 @@ public function getEnvironment()
public function getDebug()
{
if (null === $this->debug) {
throw new \RuntimeException('The "app.debug" variable is not available.');
if (null === $this->container) {
throw new \RuntimeException('The "app.debug" variable is not available.');
}

$this->debug = $this->container->getParameter('kernel.debug');
}

return $this->debug;
Expand Down

0 comments on commit b0d041f

Please sign in to comment.