12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Symfony\Bundle\TwigBundle\Extension;
- use Symfony\Bundle\TwigBundle\TokenParser\IfRoleTokenParser;
- use Symfony\Component\Security\SecurityContext;
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
- class SecurityExtension extends \Twig_Extension
- {
- protected $context;
- public function __construct(SecurityContext $context = null)
- {
- $this->context = $context;
- }
- public function vote($role, $object = null)
- {
- if (null === $this->context) {
- return false;
- }
- return $this->context->vote($role, $object);
- }
- /**
- * {@inheritdoc}
- */
- public function getGlobals()
- {
- return array(
- 'fn_has_role' => new \Twig_Function($this, 'vote'),
- );
- }
- /**
- * Returns the name of the extension.
- *
- * @return string The extension name
- */
- public function getName()
- {
- return 'security';
- }
- }
|