4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Bridge\Twig\Extension
;
14 use Symfony\Component\Security\Acl\Voter\FieldVote
;
15 use Symfony\Component\Security\Core\SecurityContextInterface
;
18 * SecurityExtension exposes security context features.
20 * @author Fabien Potencier <fabien@symfony.com>
22 class SecurityExtension
extends \Twig_Extension
26 public function __construct(SecurityContextInterface
$context = null)
28 $this->context
= $context;
31 public function isGranted($role, $object = null, $field = null)
33 if (null === $this->context
) {
37 if (null !== $field) {
38 $object = new FieldVote($object, $field);
41 return $this->context
->isGranted($role, $object);
47 public function getFunctions()
50 'is_granted' => new \
Twig_Function_Method($this, 'isGranted'),
55 * Returns the name of the extension.
57 * @return string The extension name
59 public function getName()