[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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\Authorization\AuthorizationCheckerInterface; 16 use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; 17 use Twig\Extension\AbstractExtension; 18 use Twig\TwigFunction; 19 20 /** 21 * SecurityExtension exposes security context features. 22 * 23 * @author Fabien Potencier <fabien@symfony.com> 24 */ 25 class SecurityExtension extends AbstractExtension 26 { 27 private $securityChecker; 28 29 public function __construct(AuthorizationCheckerInterface $securityChecker = null) 30 { 31 $this->securityChecker = $securityChecker; 32 } 33 34 public function isGranted($role, $object = null, $field = null) 35 { 36 if (null === $this->securityChecker) { 37 return false; 38 } 39 40 if (null !== $field) { 41 $object = new FieldVote($object, $field); 42 } 43 44 try { 45 return $this->securityChecker->isGranted($role, $object); 46 } catch (AuthenticationCredentialsNotFoundException $e) { 47 return false; 48 } 49 } 50 51 /** 52 * {@inheritdoc} 53 */ 54 public function getFunctions() 55 { 56 return [ 57 new TwigFunction('is_granted', [$this, 'isGranted']), 58 ]; 59 } 60 61 /** 62 * {@inheritdoc} 63 */ 64 public function getName() 65 { 66 return 'security'; 67 } 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |