33namespace Jade \Symfony \Traits ;
44
55use Jade \Symfony \Css ;
6- use Jade \Symfony \Logout ;
76use Jade \Symfony \MixedLoader ;
87use Symfony \Bridge \Twig \Extension \HttpFoundationExtension ;
98use Symfony \Component \DependencyInjection \ContainerInterface ;
109
1110/**
12- * @internal
13- *
1411 * Trait HelpersHandler.
12+ *
13+ * @property-read \Pug\Pug $jade
1514 */
1615trait HelpersHandler
1716{
@@ -38,7 +37,6 @@ trait HelpersHandler
3837 'assets ' ,
3938 'code ' ,
4039 'form ' ,
41- 'logout_url ' ,
4240 'request ' ,
4341 'router ' ,
4442 'security ' ,
@@ -55,8 +53,30 @@ protected function getTemplatingHelper($name)
5553 return isset ($ this ->helpers [$ name ]) ? $ this ->helpers [$ name ] : null ;
5654 }
5755
56+ protected function compileTwigCallable (\Twig_Environment $ twig , $ name )
57+ {
58+ $ callable = function () use ($ twig , $ name ) {
59+ $ variables = [];
60+ foreach (func_get_args () as $ index => $ argument ) {
61+ $ variables ['arg ' . $ index ] = $ argument ;
62+ }
63+
64+ /* @var MixedLoader $loader */
65+ $ loader = $ twig ->getLoader ();
66+
67+ $ template = $ loader ->uniqueTemplate (
68+ '{{ ' . $ name . '( ' . implode (', ' , array_keys ($ variables )) . ') }} '
69+ );
70+
71+ return $ twig ->render ($ template , $ variables );
72+ };
73+
74+ return $ callable ->bindTo ($ twig );
75+ }
76+
5877 protected function getTwigCallable (\Twig_Environment $ twig , $ function , $ name )
5978 {
79+ /* @var \Twig_Function $function */
6080 $ callable = $ function ->getCallable ();
6181
6282 if (!$ callable ||
@@ -65,19 +85,7 @@ protected function getTwigCallable(\Twig_Environment $twig, $function, $name)
6585 is_string ($ callable [0 ]) && is_string ($ callable [1 ]) &&
6686 !(new \ReflectionMethod ($ callable [0 ], $ callable [1 ]))->isStatic ()
6787 ) {
68- $ callable = function () use ($ twig , $ name ) {
69- $ variables = [];
70- foreach (func_get_args () as $ index => $ argument ) {
71- $ variables ['arg ' . $ index ] = $ argument ;
72- }
73-
74- $ template = $ twig ->getLoader ()->uniqueTemplate (
75- '{{ ' . $ name . '( ' . implode (', ' , array_keys ($ variables )) . ') }} '
76- );
77-
78- return $ twig ->render ($ template , $ variables );
79- };
80- $ callable = $ callable ->bindTo ($ twig );
88+ $ callable = $ this ->compileTwigCallable ($ twig , $ name );
8189 }
8290
8391 return $ callable ;
@@ -103,6 +111,7 @@ protected function copyTwigFunction(\Twig_Environment $twig, $function)
103111 protected function copyTwigFunctions (ContainerInterface $ services )
104112 {
105113 $ this ->twigHelpers = [];
114+
106115 if ($ services ->has ('twig ' ) &&
107116 ($ twig = $ services ->get ('twig ' )) instanceof \Twig_Environment
108117 ) {
@@ -112,6 +121,7 @@ protected function copyTwigFunctions(ContainerInterface $services)
112121 $ loader = new MixedLoader ($ twig ->getLoader ());
113122 $ twig ->setLoader ($ loader );
114123 $ this ->share ('twig ' , $ twig );
124+
115125 foreach ($ twig ->getExtensions () as $ extension ) {
116126 /* @var \Twig_Extension $extension */
117127 foreach ($ extension ->getFunctions () as $ function ) {
@@ -135,9 +145,6 @@ protected function copyStandardHelpers(ContainerInterface $services)
135145
136146 protected function copySpecialHelpers (ContainerInterface $ services )
137147 {
138- if ($ helper = $ this ->getTemplatingHelper ('logout_url ' )) {
139- $ this ->helpers ['logout ' ] = new Logout ($ helper );
140- }
141148 $ this ->helpers ['css ' ] = new Css ($ this ->getTemplatingHelper ('assets ' ));
142149 /* @var \Symfony\Component\HttpFoundation\RequestStack $stack */
143150 $ stack = $ services ->get ('request_stack ' );
@@ -167,8 +174,6 @@ protected function storeReplacements()
167174 'csrf_token ' => ['form ' , 'csrfToken ' ],
168175 'url ' => ['router ' , 'url ' ],
169176 'path ' => ['router ' , 'path ' ],
170- 'logout_url ' => ['logout ' , 'url ' ],
171- 'logout_path ' => ['logout ' , 'path ' ],
172177 'absolute_url ' => ['http ' , 'generateAbsoluteUrl ' ],
173178 'relative_path ' => ['http ' , 'generateRelativePath ' ],
174179 'is_granted ' => ['security ' , 'isGranted ' ],
0 commit comments