Explorar o código

[TwigBundle] fixed ifrole tag when security context is not enabled

Fabien Potencier %!s(int64=14) %!d(string=hai) anos
pai
achega
07eceb7ade

+ 6 - 2
src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php

@@ -27,9 +27,13 @@ class SecurityExtension extends \Twig_Extension
         $this->context = $context;
     }
 
-    public function getContext()
+    public function vote($role, $object = null)
     {
-        return $this->context;
+        if (null === $this->context) {
+            return false;
+        }
+
+        return $this->context->vote($role, $object);
     }
 
     /**

+ 1 - 1
src/Symfony/Bundle/TwigBundle/Node/IfRoleNode.php

@@ -30,7 +30,7 @@ class IfRoleNode extends \Twig_Node
     {
         $compiler
             ->addDebugInfo($this)
-            ->write('if ($this->env->getExtension(\'security\')->getContext()->vote(')
+            ->write('if ($this->env->getExtension(\'security\')->vote(')
             ->subcompile($this->getNode('role'))
         ;