[TwigBundle] added the security context and the user as global variables when they are defined

This commit is contained in:
Fabien Potencier 2011-01-07 17:49:43 +01:00
parent 1c3a01b25c
commit 50809d2ae0

View File

@ -4,6 +4,7 @@ namespace Symfony\Bundle\TwigBundle\Renderer;
use Symfony\Component\Templating\Renderer\Renderer as BaseRenderer;
use Symfony\Component\Templating\Storage\Storage;
use Symfony\Component\Templating\Engine;
/*
* This file is part of the Symfony package.
@ -27,6 +28,24 @@ class Renderer extends BaseRenderer
$this->environment = $environment;
}
/**
* {@inheritdoc}
*/
public function setEngine(Engine $engine)
{
parent::setEngine($engine);
$container = $engine->getContainer();
if ($container->has('security.context')) {
$security = $container->get('security.context');
$this->environment->addGlobal('security', $security);
if ($user = $security->getUser()) {
$this->environment->addGlobal('user', $user);
}
}
}
/**
* Evaluates a template.
*