feature #13233 [TwigBundle] removed deprecated ActionsExtension (fabpot)

This PR was merged into the 3.0-dev branch.

Discussion
----------

[TwigBundle] removed deprecated ActionsExtension

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

This removes the `{% render %}` tags which was replaced by the `{{ render }}` function in 2.2.

Commits
-------

70cd6c9 [TwigBundle] removed deprecated ActionsExtension
This commit is contained in:
Fabien Potencier 2015-01-14 11:57:12 +01:00
commit 6a6d9c3805
6 changed files with 0 additions and 260 deletions

View File

@ -28,10 +28,6 @@ class ExtensionPass implements CompilerPassInterface
$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');
}

View File

@ -1,84 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <fabien@symfony.com>
*
* @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())
{
trigger_error('The Twig render tag was deprecated in version 2.2 and will be removed in version 3.0. Use the Twig render function instead.', E_USER_DEPRECATED);
$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';
}
}

View File

@ -1,44 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <fabien@symfony.com>
*
* @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")
;
}
}

View File

@ -12,7 +12,6 @@
<parameter key="twig.cache_warmer.class">Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer</parameter>
<parameter key="twig.extension.trans.class">Symfony\Bridge\Twig\Extension\TranslationExtension</parameter>
<parameter key="twig.extension.assets.class">Symfony\Bundle\TwigBundle\Extension\AssetsExtension</parameter>
<parameter key="twig.extension.actions.class">Symfony\Bundle\TwigBundle\Extension\ActionsExtension</parameter>
<parameter key="twig.extension.code.class">Symfony\Bridge\Twig\Extension\CodeExtension</parameter>
<parameter key="twig.extension.routing.class">Symfony\Bridge\Twig\Extension\RoutingExtension</parameter>
<parameter key="twig.extension.yaml.class">Symfony\Bridge\Twig\Extension\YamlExtension</parameter>
@ -81,10 +80,6 @@
<argument type="service" id="router.request_context" on-invalid="null" />
</service>
<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
<argument type="service" id="fragment.handler" />
</service>
<service id="twig.extension.code" class="%twig.extension.code.class%" public="false">
<tag name="twig.extension" />
<argument /> <!-- %templating.helper.code.file_link_format% -->

View File

@ -1,64 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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'
),
),
);
}
}

View File

@ -1,59 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <fabien@symfony.com>
*
* @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';
}
}