[TwigBundle] removed the Container dependency on ActionsExtension
This commit is contained in:
parent
59f3751052
commit
76abf98bff
@ -27,6 +27,10 @@ class ExtensionPass implements CompilerPassInterface
|
|||||||
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
|
$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')) {
|
if ($container->has('translator')) {
|
||||||
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
|
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
namespace Symfony\Bundle\TwigBundle\Extension;
|
namespace Symfony\Bundle\TwigBundle\Extension;
|
||||||
|
|
||||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for Symfony actions helper.
|
* Twig extension for Symfony actions helper.
|
||||||
@ -24,16 +24,26 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
*/
|
*/
|
||||||
class ActionsExtension extends \Twig_Extension
|
class ActionsExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
private $container;
|
private $handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* @param FragmentHandler|ContainerInterface $handler
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container The service container
|
* @deprecated Passing a ContainerInterface as a first argument is deprecated as of 2.7 and will be removed in 3.0.
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct($handler)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
if ($handler instanceof FragmentHandler) {
|
||||||
|
$this->handler = $handler;
|
||||||
|
} elseif ($handler instanceof ContainerInterface) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,11 +52,14 @@ class ActionsExtension extends \Twig_Extension
|
|||||||
* @param string $uri A URI
|
* @param string $uri A URI
|
||||||
* @param array $options An array of options
|
* @param array $options An array of options
|
||||||
*
|
*
|
||||||
* @see ActionsHelper::render()
|
* @see FragmentHandler::render()
|
||||||
*/
|
*/
|
||||||
public function renderUri($uri, array $options = array())
|
public function renderUri($uri, array $options = array())
|
||||||
{
|
{
|
||||||
return $this->container->get('templating.helper.actions')->render($uri, $options);
|
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
|
||||||
|
unset($options['strategy']);
|
||||||
|
|
||||||
|
return $this->handler->render($uri, $strategy, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,8 +71,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
|
<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
|
||||||
<tag name="twig.extension" />
|
<argument type="service" id="fragment.handler" />
|
||||||
<argument type="service" id="service_container" />
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.code" class="%twig.extension.code.class%" public="false">
|
<service id="twig.extension.code" class="%twig.extension.code.class%" public="false">
|
||||||
|
Reference in New Issue
Block a user