Navigation Menu

Skip to content

Commit

Permalink
[TwigBundle] removed the Container dependency on ActionsExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 4, 2015
1 parent 59f3751 commit 76abf98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Expand Up @@ -27,6 +27,10 @@ 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');
}
Expand Down
29 changes: 21 additions & 8 deletions src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
Expand Up @@ -12,8 +12,8 @@
namespace Symfony\Bundle\TwigBundle\Extension;

use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;

/**
* Twig extension for Symfony actions helper.
Expand All @@ -24,16 +24,26 @@
*/
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;
}

/**
Expand All @@ -42,11 +52,14 @@ public function __construct(ContainerInterface $container)
* @param string $uri A URI
* @param array $options An array of options
*
* @see ActionsHelper::render()
* @see FragmentHandler::render()
*/
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);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -71,8 +71,7 @@
</service>

<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="service_container" />
<argument type="service" id="fragment.handler" />
</service>

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

0 comments on commit 76abf98

Please sign in to comment.