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

Skip to content

Commit 21c33b3

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

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
1515
use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
1718

1819
/**
1920
* Twig extension for Symfony actions helper.
@@ -24,16 +25,26 @@
2425
*/
2526
class ActionsExtension extends \Twig_Extension
2627
{
27-
private $container;
28+
private $handler;
2829

2930
/**
30-
* Constructor.
31+
* @param FragmentHandler|ContainerInterface $handler
3132
*
32-
* @param ContainerInterface $container The service container
33+
* @deprecated Passing a ContainerInterface as a first argument is deprecated as of 2.7 and will be removed in 3.0.
3334
*/
34-
public function __construct(ContainerInterface $container)
35+
public function __construct($handler)
3536
{
36-
$this->container = $container;
37+
if ($handler instanceof FragmentHandler) {
38+
$this->handler = $handler;
39+
} elseif ($handler instanceof ContainerInterface) {
40+
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);
41+
42+
$this->handler = $handler->get('fragment.handler');
43+
} else {
44+
throw new \BadFunctionCallException(sprintf('%s takes a FragmentHandler or a ContainerInterface object as its first argument.', __METHOD__));
45+
}
46+
47+
$this->handler = $handler;
3748
}
3849

3950
/**
@@ -42,11 +53,14 @@ public function __construct(ContainerInterface $container)
4253
* @param string $uri A URI
4354
* @param array $options An array of options
4455
*
45-
* @see ActionsHelper::render()
56+
* @see FragmentHandler::render()
4657
*/
4758
public function renderUri($uri, array $options = array())
4859
{
49-
return $this->container->get('templating.helper.actions')->render($uri, $options);
60+
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
61+
unset($options['strategy']);
62+
63+
return $this->handler->render($uri, $strategy, $options);
5064
}
5165

5266
/**

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)