From 70cd6c9a4da2270b46a124a3456f938d5a120a3e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 4 Jan 2015 11:54:57 +0100 Subject: [PATCH] [TwigBundle] removed deprecated ActionsExtension --- .../Compiler/ExtensionPass.php | 4 - .../TwigBundle/Extension/ActionsExtension.php | 82 ------------------- .../Bundle/TwigBundle/Node/RenderNode.php | 44 ---------- .../TwigBundle/Resources/config/twig.xml | 5 -- .../LegacyRenderTokenParserTest.php | 64 --------------- .../TokenParser/RenderTokenParser.php | 59 ------------- 6 files changed, 258 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php delete mode 100644 src/Symfony/Bundle/TwigBundle/Node/RenderNode.php delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php delete mode 100644 src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index 641c5df155b5f..069083d27f0f0 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -27,10 +27,6 @@ public function process(ContainerBuilder $container) $container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form')); } - if ($container->has('fragment.handler')) { - $container->getDefinition('twig.extension.actions')->addTag('twig.extension'); - } - if ($container->has('translator')) { $container->getDefinition('twig.extension.trans')->addTag('twig.extension'); } diff --git a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php deleted file mode 100644 index 9209a60db2d95..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Extension; - -use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Fragment\FragmentHandler; - -/** - * Twig extension for Symfony actions helper. - * - * @author Fabien Potencier - * - * @deprecated since version 2.2, to be removed in 3.0. - */ -class ActionsExtension extends \Twig_Extension -{ - private $handler; - - /** - * @param FragmentHandler|ContainerInterface $handler - * - * @deprecated Passing a ContainerInterface as a first argument is deprecated since 2.7 and will be removed in 3.0. - */ - public function __construct($handler) - { - if ($handler instanceof FragmentHandler) { - $this->handler = $handler; - } elseif ($handler instanceof ContainerInterface) { - trigger_error('The ability to pass a ContainerInterface instance as a first argument to '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Pass a FragmentHandler instance instead.', E_USER_DEPRECATED); - - $this->handler = $handler->get('fragment.handler'); - } else { - throw new \BadFunctionCallException(sprintf('%s takes a FragmentHandler or a ContainerInterface object as its first argument.', __METHOD__)); - } - - $this->handler = $handler; - } - - /** - * Returns the Response content for a given URI. - * - * @param string $uri A URI - * @param array $options An array of options - * - * @see FragmentHandler::render() - */ - public function renderUri($uri, array $options = array()) - { - $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline'; - unset($options['strategy']); - - return $this->handler->render($uri, $strategy, $options); - } - - /** - * Returns the token parser instance to add to the existing list. - * - * @return array An array of \Twig_TokenParser instances - */ - public function getTokenParsers() - { - return array( - // {% render url('post_list', { 'limit': 2 }), { 'alt': 'BlogBundle:Post:error' } %} - new RenderTokenParser(), - ); - } - - public function getName() - { - return 'actions'; - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php deleted file mode 100644 index 1c590f9ac8aa3..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Node; - -/** - * Represents a render node. - * - * @author Fabien Potencier - * - * @deprecated since version 2.2, to be removed in 3.0. - */ -class RenderNode extends \Twig_Node -{ - public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $options, $lineno, $tag = null) - { - parent::__construct(array('expr' => $expr, 'options' => $options), array(), $lineno, $tag); - } - - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler $compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("echo \$this->env->getExtension('actions')->renderUri(") - ->subcompile($this->getNode('expr')) - ->raw(', ') - ->subcompile($this->getNode('options')) - ->raw(");\n") - ; - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 4ff841db1cef1..8ccb5c61750b4 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -12,7 +12,6 @@ Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer Symfony\Bridge\Twig\Extension\TranslationExtension Symfony\Bundle\TwigBundle\Extension\AssetsExtension - Symfony\Bundle\TwigBundle\Extension\ActionsExtension Symfony\Bridge\Twig\Extension\CodeExtension Symfony\Bridge\Twig\Extension\RoutingExtension Symfony\Bridge\Twig\Extension\YamlExtension @@ -70,10 +69,6 @@ - - - - %templating.helper.code.file_link_format% diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php deleted file mode 100644 index 3e415abf3e9e7..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\TokenParser; - -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; -use Symfony\Bundle\TwigBundle\Node\RenderNode; - -class LegacyRenderTokenParserTest extends TestCase -{ - public function setUp() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - } - - /** - * @dataProvider getTestsForRender - */ - public function testCompile($source, $expected) - { - $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); - $env->addTokenParser(new RenderTokenParser()); - $stream = $env->tokenize($source); - $parser = new \Twig_Parser($env); - - $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); - } - - public function getTestsForRender() - { - return array( - array( - '{% render "foo" %}', - new RenderNode( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Array(array(), 1), - 1, - 'render' - ), - ), - array( - '{% render "foo", {foo: 1} %}', - new RenderNode( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Array(array( - new \Twig_Node_Expression_Constant('foo', 1), - new \Twig_Node_Expression_Constant('1', 1), - ), 1), - 1, - 'render' - ), - ), - ); - } -} diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php deleted file mode 100644 index 0d3ae2b86d122..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/RenderTokenParser.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\TokenParser; - -use Symfony\Bundle\TwigBundle\Node\RenderNode; - -/** - * Token Parser for the render tag. - * - * @author Fabien Potencier - * - * @deprecated since version 2.2, to be removed in 3.0. - */ -class RenderTokenParser extends \Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param \Twig_Token $token A \Twig_Token instance - * - * @return \Twig_NodeInterface A \Twig_NodeInterface instance - */ - public function parse(\Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - // options - if ($this->parser->getStream()->test(\Twig_Token::PUNCTUATION_TYPE, ',')) { - $this->parser->getStream()->next(); - - $options = $this->parser->getExpressionParser()->parseExpression(); - } else { - $options = new \Twig_Node_Expression_Array(array(), $token->getLine()); - } - - $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); - - return new RenderNode($expr, $options, $token->getLine(), $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'render'; - } -}