2
2
3
3
namespace ZfcTwig \View \Renderer ;
4
4
5
- use RuntimeException ;
6
5
use Twig_Environment ;
7
6
use Zend \View \Exception ;
8
7
use Zend \View \HelperPluginManager ;
9
8
use Zend \View \Model \ModelInterface ;
10
9
use Zend \View \Renderer \RendererInterface ;
11
10
use Zend \View \Resolver \ResolverInterface ;
12
-
13
11
use ZfcTwig \View \Resolver \TwigResolver ;
14
12
15
13
class TwigRenderer implements RendererInterface
@@ -30,14 +28,44 @@ class TwigRenderer implements RendererInterface
30
28
protected $ resolver ;
31
29
32
30
/**
33
- * @param Twig_Environment $environment
31
+ * @var array Cache for the plugin call
32
+ */
33
+ private $ __pluginCache = array ();
34
+
35
+ /**
36
+ * @param \Twig_Environment $environment
37
+ * @param TwigResolver $resolver
34
38
*/
35
39
public function __construct (Twig_Environment $ environment , TwigResolver $ resolver )
36
40
{
37
41
$ this ->environment = $ environment ;
38
42
$ this ->resolver = $ resolver ;
39
43
}
40
44
45
+ /**
46
+ * Overloading: proxy to helpers
47
+ *
48
+ * Proxies to the attached plugin manager to retrieve, return, and potentially
49
+ * execute helpers.
50
+ *
51
+ * * If the helper does not define __invoke, it will be returned
52
+ * * If the helper does define __invoke, it will be called as a functor
53
+ *
54
+ * @param string $method
55
+ * @param array $argv
56
+ * @return mixed
57
+ */
58
+ public function __call ($ method , $ argv )
59
+ {
60
+ if (!isset ($ this ->__pluginCache [$ method ])) {
61
+ $ this ->__pluginCache [$ method ] = $ this ->plugin ($ method );
62
+ }
63
+ if (is_callable ($ this ->__pluginCache [$ method ])) {
64
+ return call_user_func_array ($ this ->__pluginCache [$ method ], $ argv );
65
+ }
66
+ return $ this ->__pluginCache [$ method ];
67
+ }
68
+
41
69
/**
42
70
* Get plugin instance, proxy to HelperPluginManager::get
43
71
*
0 commit comments