aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php')
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php63
1 files changed, 63 insertions, 0 deletions
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 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Extension;
13
14use Symfony\Component\Security\Acl\Voter\FieldVote;
15use Symfony\Component\Security\Core\SecurityContextInterface;
16
17/**
18 * SecurityExtension exposes security context features.
19 *
20 * @author Fabien Potencier <fabien@symfony.com>
21 */
22class SecurityExtension extends \Twig_Extension
23{
24 private $context;
25
26 public function __construct(SecurityContextInterface $context = null)
27 {
28 $this->context = $context;
29 }
30
31 public function isGranted($role, $object = null, $field = null)
32 {
33 if (null === $this->context) {
34 return false;
35 }
36
37 if (null !== $field) {
38 $object = new FieldVote($object, $field);
39 }
40
41 return $this->context->isGranted($role, $object);
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function getFunctions()
48 {
49 return array(
50 'is_granted' => new \Twig_Function_Method($this, 'isGranted'),
51 );
52 }
53
54 /**
55 * Returns the name of the extension.
56 *
57 * @return string The extension name
58 */
59 public function getName()
60 {
61 return 'security';
62 }
63}