Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9427bce

Browse files
committed
[TwigBundle] removed the Container dependency on ActionsExtension
1 parent 7e660fd commit 9427bce

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function process(ContainerBuilder $container)
2727
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
2828
}
2929

30+
if ($container->has('fragment.handler')) {
31+
$container->getDefinition('twig.extension.actions')->addTag('twig.extension');
32+
}
33+
3034
if ($container->has('translator')) {
3135
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
3236
}

src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Bundle\TwigBundle\Extension;
1313

1414
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
15-
use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper;
1615
use Symfony\Component\DependencyInjection\ContainerInterface;
16+
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
1717

1818
/**
1919
* Twig extension for Symfony actions helper.
@@ -24,16 +24,26 @@
2424
*/
2525
class ActionsExtension extends \Twig_Extension
2626
{
27-
private $container;
27+
private $handler;
2828

2929
/**
30-
* Constructor.
30+
* @param FragmentHandler|ContainerInterface $handler
3131
*
32-
* @param ContainerInterface $container The service container
32+
* @deprecated Passing a ContainerInterface as a first argument is deprecated as of 2.7 and will be removed in 3.0.
3333
*/
34-
public function __construct(ContainerInterface $container)
34+
public function __construct($handler)
3535
{
36-
$this->container = $container;
36+
if ($handler instanceof FragmentHandler) {
37+
$this->handler = $handler;
38+
} elseif ($handler instanceof ContainerInterface) {
39+
trigger_error(sprintf('The ability to pass a ContainerInterface instance as a first argument to %s was deprecated in 2.7 and will be removed in 3.0. Please, pass a FragmentHandler instance instead.', __METHOD__), E_USER_DEPRECATED);
40+
41+
$this->handler = $handler->get('fragment.handler');
42+
} else {
43+
throw new \BadFunctionCallException(sprintf('%s takes a FragmentHandler or a ContainerInterface object as its first argument.', __METHOD__));
44+
}
45+
46+
$this->handler = $handler;
3747
}
3848

3949
/**
@@ -42,11 +52,14 @@ public function __construct(ContainerInterface $container)
4252
* @param string $uri A URI
4353
* @param array $options An array of options
4454
*
45-
* @see ActionsHelper::render()
55+
* @see FragmentHandler::render()
4656
*/
4757
public function renderUri($uri, array $options = array())
4858
{
49-
return $this->container->get('templating.helper.actions')->render($uri, $options);
59+
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
60+
unset($options['strategy']);
61+
62+
return $this->handler->render($uri, $strategy, $options);
5063
}
5164

5265
/**

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
</service>
7272

7373
<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
74-
<tag name="twig.extension" />
75-
<argument type="service" id="service_container" />
74+
<argument type="service" id="fragment.handler" />
7675
</service>
7776

7877
<service id="twig.extension.code" class="%twig.extension.code.class%" public="false">

0 commit comments

Comments
 (0)