@@ -33,15 +33,18 @@ class PhpEngine implements EngineInterface, \ArrayAccess
33
33
protected $ cache ;
34
34
protected $ escapers ;
35
35
protected $ globals ;
36
+ protected $ parser ;
36
37
37
38
/**
38
39
* Constructor.
39
40
*
40
- * @param LoaderInterface $loader A loader instance
41
- * @param array $helpers An array of helper instances
41
+ * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
42
+ * @param LoaderInterface $loader A loader instance
43
+ * @param array $helpers An array of helper instances
42
44
*/
43
- public function __construct (LoaderInterface $ loader , array $ helpers = array ())
45
+ public function __construct (TemplateNameParserInterface $ parser , LoaderInterface $ loader , array $ helpers = array ())
44
46
{
47
+ $ this ->parser = $ parser ;
45
48
$ this ->loader = $ loader ;
46
49
$ this ->parents = array ();
47
50
$ this ->stack = array ();
@@ -60,8 +63,8 @@ public function __construct(LoaderInterface $loader, array $helpers = array())
60
63
/**
61
64
* Renders a template.
62
65
*
63
- * @param string $name A template name
64
- * @param array $parameters An array of parameters to pass to the template
66
+ * @param mixed $name A template name
67
+ * @param array $parameters An array of parameters to pass to the template
65
68
*
66
69
* @return string The evaluated template as a string
67
70
*
@@ -100,7 +103,7 @@ public function render($name, array $parameters = array())
100
103
/**
101
104
* Returns true if the template exists.
102
105
*
103
- * @param string $name A template name
106
+ * @param mixed $name A template name
104
107
*
105
108
* @return Boolean true if the template exists, false otherwise
106
109
*/
@@ -118,40 +121,43 @@ public function exists($name)
118
121
/**
119
122
* Loads the given template.
120
123
*
121
- * @param string $name A template name
124
+ * @param mixed $name A template name
122
125
*
123
126
* @return Storage A Storage instance
124
127
*
125
128
* @throws \InvalidArgumentException if the template cannot be found
126
129
*/
127
130
public function load ($ name )
128
131
{
129
- if (isset ($ this ->cache [$ name ])) {
130
- return $ this ->cache [$ name ];
132
+ $ template = $ this ->parser ->parse ($ name );
133
+
134
+ $ key = md5 (serialize ($ template ));
135
+ if (isset ($ this ->cache [$ key ])) {
136
+ return $ this ->cache [$ key ];
131
137
}
132
138
133
139
// load
134
- $ template = $ this ->loader ->load ($ name );
140
+ $ template = $ this ->loader ->load ($ template );
135
141
136
142
if (false === $ template ) {
137
143
throw new \InvalidArgumentException (sprintf ('The template "%s" does not exist. ' , $ name ));
138
144
}
139
145
140
- $ this ->cache [$ name ] = $ template ;
141
-
142
- return $ template ;
146
+ return $ this ->cache [$ key ] = $ template ;
143
147
}
144
148
145
149
/**
146
150
* Returns true if this class is able to render the given template.
147
151
*
148
- * @param string $name A template name
152
+ * @param mixed $name A template name
149
153
*
150
154
* @return Boolean True if this class supports the given resource, false otherwise
151
155
*/
152
156
public function supports ($ name )
153
157
{
154
- return false !== strpos ($ name , '.php ' );
158
+ $ template = $ this ->parser ->parse ($ name );
159
+
160
+ return 'php ' === $ template ['engine ' ];
155
161
}
156
162
157
163
/**
0 commit comments