kekrozsak/vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/Twig/SecurityExtension.php
Polonkai Gergely 082a0130c2 Initial commit with Symfony 2.1+Vendors
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
2012-07-01 09:52:20 +02:00

35 lines
817 B
PHP

<?php
namespace JMS\SecurityExtraBundle\Twig;
use JMS\SecurityExtraBundle\Security\Authorization\Expression\Expression;
use Symfony\Component\Security\Core\SecurityContextInterface;
class SecurityExtension extends \Twig_Extension
{
private $context;
public function __construct(SecurityContextInterface $context)
{
$this->context = $context;
}
public function getFunctions()
{
return array(
'is_expr_granted' => new \Twig_Function_Method($this, 'isExprGranted', array(
'is_safe' => true,
)),
);
}
public function isExprGranted($expr, $object = null)
{
return $this->context->isGranted(array(new Expression($expr)), $object);
}
public function getName()
{
return 'jms_security_extra';
}
}