diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/SecurityExtension.php | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
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.php | 63 |
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 | |||
12 | namespace Symfony\Bridge\Twig\Extension; | ||
13 | |||
14 | use Symfony\Component\Security\Acl\Voter\FieldVote; | ||
15 | use Symfony\Component\Security\Core\SecurityContextInterface; | ||
16 | |||
17 | /** | ||
18 | * SecurityExtension exposes security context features. | ||
19 | * | ||
20 | * @author Fabien Potencier <fabien@symfony.com> | ||
21 | */ | ||
22 | class 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 | } | ||