Преглед на файлове

[TwigBundle] replaced the ifrole tag with a has_role function

Before:

{% ifrole "ROLE_ADMIN" %}
    Only show if you have the ROLE_ADMIN role...
{% endifrole %}

After:

{% if has_role("ROLE_ADMIN") %}
    Only show if you have the ROLE_ADMIN role...
{% endif %}
Fabien Potencier преди 14 години
родител
ревизия
faac8e6ffd

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

@@ -39,20 +39,10 @@ class SecurityExtension extends \Twig_Extension
     /**
      * {@inheritdoc}
      */
-    public function getFilters()
+    public function getGlobals()
     {
         return array(
-        );
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getTokenParsers()
-    {
-        return array(
-            // {% ifrole "ROLE_ADMIN" %}something{% endifrole %}
-            new IfRoleTokenParser(),
+            'has_role' => new \Twig_Function($this, 'vote'),
         );
     }
 

+ 0 - 52
src/Symfony/Bundle/TwigBundle/Node/IfRoleNode.php

@@ -1,52 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\Node;
-
-/*
- * 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 IfRoleNode extends \Twig_Node
-{
-    public function __construct(\Twig_NodeInterface $role, \Twig_NodeInterface $object = null, \Twig_NodeInterface $body, $lineno, $tag = null)
-    {
-        parent::__construct(array('role' => $role, 'object' => $object, 'body' => $body), array(), $lineno, $tag);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function compile($compiler)
-    {
-        $compiler
-            ->addDebugInfo($this)
-            ->write('if ($this->env->getExtension(\'security\')->vote(')
-            ->subcompile($this->getNode('role'))
-        ;
-
-        if (null !== $this->getNode('object')) {
-            $compiler
-                ->raw(', ')
-                ->subcompile($this->getNode('object'))
-            ;
-        }
-
-        $compiler
-            ->write(')) {')
-            ->indent()
-            ->subcompile($this->getNode('body'))
-            ->outdent()
-            ->write('}')
-        ;
-    }
-}

+ 0 - 59
src/Symfony/Bundle/TwigBundle/TokenParser/IfRoleTokenParser.php

@@ -1,59 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\TokenParser;
-
-use Symfony\Bundle\TwigBundle\Node\IfRoleNode;
-
-/*
- * 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 IfRoleTokenParser extends \Twig_TokenParser
-{
-    /**
-     * {@inheritdoc}
-     */
-    public function parse(\Twig_Token $token)
-    {
-        $stream = $this->parser->getStream();
-
-        $role = $this->parser->getExpressionParser()->parseExpression();
-
-        $object = null;
-        if ($stream->test('for')) {
-            $stream->next();
-            $object = $this->parser->getExpressionParser()->parseExpression();
-        }
-
-        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
-        $body = $this->parser->subparse(array($this, 'decideIfRoleFork'), true);
-        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
-
-        return new IfRoleNode($role, $object, $body, $token->getLine(), $this->getTag());
-    }
-
-    public function decideIfRoleFork($token)
-    {
-        return $token->test(array('endifrole'));
-    }
-
-    /**
-     * Gets the tag name associated with this token parser.
-     *
-     * @param string The tag name
-     */
-    public function getTag()
-    {
-        return 'ifrole';
-    }
-}