This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php

59 lines
1.2 KiB
PHP
Raw Normal View History

<?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, $field = null)
{
if (null === $this->context) {
return false;
}
2011-01-07 16:14:20 +00:00
return $this->context->vote($role, $object, $field);
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array(
'has_role' => new \Twig_Function_Method($this, 'vote'),
);
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'security';
}
}