From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Bridge/Twig/Extension/SecurityExtension.php | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php') diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php new file mode 100644 index 00000000..c9f4466c --- /dev/null +++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Twig\Extension; + +use Symfony\Component\Security\Acl\Voter\FieldVote; +use Symfony\Component\Security\Core\SecurityContextInterface; + +/** + * SecurityExtension exposes security context features. + * + * @author Fabien Potencier + */ +class SecurityExtension extends \Twig_Extension +{ + private $context; + + public function __construct(SecurityContextInterface $context = null) + { + $this->context = $context; + } + + public function isGranted($role, $object = null, $field = null) + { + if (null === $this->context) { + return false; + } + + if (null !== $field) { + $object = new FieldVote($object, $field); + } + + return $this->context->isGranted($role, $object); + } + + /** + * {@inheritdoc} + */ + public function getFunctions() + { + return array( + 'is_granted' => new \Twig_Function_Method($this, 'isGranted'), + ); + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'security'; + } +} -- cgit v1.2.3