12
12
namespace Symfony \Bundle \TwigBundle \Extension ;
13
13
14
14
use Symfony \Bundle \TwigBundle \TokenParser \RenderTokenParser ;
15
- use Symfony \Bundle \FrameworkBundle \Templating \Helper \ActionsHelper ;
16
15
use Symfony \Component \DependencyInjection \ContainerInterface ;
16
+ use Symfony \Component \HttpKernel \Fragment \FragmentHandler ;
17
17
18
18
/**
19
19
* Twig extension for Symfony actions helper.
24
24
*/
25
25
class ActionsExtension extends \Twig_Extension
26
26
{
27
- private $ container ;
27
+ private $ handler ;
28
28
29
29
/**
30
- * Constructor.
30
+ * @param FragmentHandler|ContainerInterface $handler
31
31
*
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.
33
33
*/
34
- public function __construct (ContainerInterface $ container )
34
+ public function __construct ($ handler )
35
35
{
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 ;
37
47
}
38
48
39
49
/**
@@ -42,11 +52,14 @@ public function __construct(ContainerInterface $container)
42
52
* @param string $uri A URI
43
53
* @param array $options An array of options
44
54
*
45
- * @see ActionsHelper ::render()
55
+ * @see FragmentHandler ::render()
46
56
*/
47
57
public function renderUri ($ uri , array $ options = array ())
48
58
{
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 );
50
63
}
51
64
52
65
/**
0 commit comments