|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3Fluid\Fluid\Core\Rendering; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file belongs to the package "TYPO3 Fluid". |
|
6
|
|
|
* See LICENSE.txt that was shipped with this package. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use TYPO3Fluid\Fluid\Core\ErrorHandler\StandardErrorHandler; |
|
10
|
|
|
use TYPO3Fluid\Fluid\Core\ErrorHandler\ErrorHandlerInterface; |
|
11
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\Configuration; |
|
12
|
|
|
use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface; |
|
13
|
|
|
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler; |
|
14
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\Interceptor\Escape; |
|
15
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode; |
|
16
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\MathExpressionNode; |
|
17
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\TernaryExpressionNode; |
|
18
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\TemplateParser; |
|
19
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor; |
|
20
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor; |
|
21
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor; |
|
22
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessorInterface; |
|
23
|
|
|
use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider; |
|
24
|
|
|
use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface; |
|
25
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker; |
|
26
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperResolver; |
|
27
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer; |
|
28
|
|
|
use TYPO3Fluid\Fluid\View\TemplatePaths; |
|
29
|
|
|
use TYPO3Fluid\Fluid\View\ViewInterface; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The rendering context that contains useful information during rendering time of a Fluid template |
|
33
|
|
|
*/ |
|
34
|
|
|
class RenderingContext implements RenderingContextInterface |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @var ErrorHandlerInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $errorHandler; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Template Variable Container. Contains all variables available through object accessors in the template |
|
43
|
|
|
* |
|
44
|
|
|
* @var VariableProviderInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $variableProvider; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* ViewHelper Variable Container |
|
50
|
|
|
* |
|
51
|
|
|
* @var ViewHelperVariableContainer |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $viewHelperVariableContainer; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var ViewHelperResolver |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $viewHelperResolver; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var ViewHelperInvoker |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $viewHelperInvoker; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var TemplatePaths |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $templatePaths; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $controllerName; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var string |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $controllerAction; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var ViewInterface |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $view; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var TemplateParser |
|
87
|
|
|
*/ |
|
88
|
|
|
protected $templateParser; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var TemplateCompiler |
|
92
|
|
|
*/ |
|
93
|
|
|
protected $templateCompiler; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var FluidCacheInterface |
|
97
|
|
|
*/ |
|
98
|
|
|
protected $cache; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var TemplateProcessorInterface[] |
|
102
|
|
|
*/ |
|
103
|
|
|
protected $templateProcessors = []; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* List of class names implementing ExpressionNodeInterface |
|
107
|
|
|
* which will be consulted when an expression does not match |
|
108
|
|
|
* any built-in parser expression types. |
|
109
|
|
|
* |
|
110
|
|
|
* @var array |
|
111
|
|
|
*/ |
|
112
|
|
|
protected $expressionNodeTypes = [ |
|
113
|
|
|
CastingExpressionNode::class, |
|
114
|
|
|
MathExpressionNode::class, |
|
115
|
|
|
TernaryExpressionNode::class, |
|
116
|
|
|
]; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Constructor |
|
120
|
|
|
* |
|
121
|
|
|
* Constructing a RenderingContext should result in an object containing instances |
|
122
|
|
|
* in all properties of the object. Subclassing RenderingContext allows changing the |
|
123
|
|
|
* types of instances that are created. |
|
124
|
|
|
* |
|
125
|
|
|
* Setters are used to fill the object instances. Some setters will call the |
|
126
|
|
|
* setRenderingContext() method (convention name) to provide the instance that is |
|
127
|
|
|
* created with an instance of the "parent" RenderingContext. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function __construct(ViewInterface $view) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->view = $view; |
|
132
|
|
|
$this->setTemplateParser(new TemplateParser()); |
|
133
|
|
|
$this->setTemplateCompiler(new TemplateCompiler()); |
|
134
|
|
|
$this->setTemplatePaths(new TemplatePaths()); |
|
135
|
|
|
$this->setTemplateProcessors( |
|
136
|
|
|
[ |
|
137
|
|
|
new EscapingModifierTemplateProcessor(), |
|
138
|
|
|
new PassthroughSourceModifierTemplateProcessor(), |
|
139
|
|
|
new NamespaceDetectionTemplateProcessor() |
|
140
|
|
|
] |
|
141
|
|
|
); |
|
142
|
|
|
$this->setViewHelperResolver(new ViewHelperResolver()); |
|
143
|
|
|
$this->setViewHelperInvoker(new ViewHelperInvoker()); |
|
144
|
|
|
$this->setViewHelperVariableContainer(new ViewHelperVariableContainer()); |
|
145
|
|
|
$this->setVariableProvider(new StandardVariableProvider()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return ErrorHandlerInterface |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getErrorHandler() |
|
152
|
|
|
{ |
|
153
|
|
|
return isset($this->errorHandler) ? $this->errorHandler : new StandardErrorHandler(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param ErrorHandlerInterface $errorHandler |
|
158
|
|
|
* @return void |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setErrorHandler(ErrorHandlerInterface $errorHandler) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->errorHandler = $errorHandler; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Injects the template variable container containing all variables available through ObjectAccessors |
|
167
|
|
|
* in the template |
|
168
|
|
|
* |
|
169
|
|
|
* @param VariableProviderInterface $variableProvider The template variable container to set |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setVariableProvider(VariableProviderInterface $variableProvider) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->variableProvider = $variableProvider; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Get the template variable container |
|
178
|
|
|
* |
|
179
|
|
|
* @return VariableProviderInterface The Template Variable Container |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getVariableProvider() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->variableProvider; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return ViewHelperResolver |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getViewHelperResolver() |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->viewHelperResolver; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param ViewHelperResolver $viewHelperResolver |
|
196
|
|
|
* @return void |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setViewHelperResolver(ViewHelperResolver $viewHelperResolver) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->viewHelperResolver = $viewHelperResolver; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @return ViewHelperInvoker |
|
205
|
|
|
*/ |
|
206
|
|
|
public function getViewHelperInvoker() |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->viewHelperInvoker; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param ViewHelperInvoker $viewHelperInvoker |
|
213
|
|
|
* @return void |
|
214
|
|
|
*/ |
|
215
|
|
|
public function setViewHelperInvoker(ViewHelperInvoker $viewHelperInvoker) |
|
216
|
|
|
{ |
|
217
|
|
|
$this->viewHelperInvoker = $viewHelperInvoker; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return TemplatePaths |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getTemplatePaths() |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->templatePaths; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @param TemplatePaths $templatePaths |
|
230
|
|
|
* @return void |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setTemplatePaths(TemplatePaths $templatePaths) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->templatePaths = $templatePaths; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Set the ViewHelperVariableContainer |
|
239
|
|
|
* |
|
240
|
|
|
* @param ViewHelperVariableContainer $viewHelperVariableContainer |
|
241
|
|
|
* @return void |
|
242
|
|
|
*/ |
|
243
|
|
|
public function setViewHelperVariableContainer(ViewHelperVariableContainer $viewHelperVariableContainer) |
|
244
|
|
|
{ |
|
245
|
|
|
$this->viewHelperVariableContainer = $viewHelperVariableContainer; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Get the ViewHelperVariableContainer |
|
250
|
|
|
* |
|
251
|
|
|
* @return ViewHelperVariableContainer |
|
252
|
|
|
*/ |
|
253
|
|
|
public function getViewHelperVariableContainer() |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->viewHelperVariableContainer; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Inject the Template Parser |
|
260
|
|
|
* |
|
261
|
|
|
* @param TemplateParser $templateParser The template parser |
|
262
|
|
|
* @return void |
|
263
|
|
|
*/ |
|
264
|
|
|
public function setTemplateParser(TemplateParser $templateParser) |
|
265
|
|
|
{ |
|
266
|
|
|
$this->templateParser = $templateParser; |
|
267
|
|
|
$this->templateParser->setRenderingContext($this); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return TemplateParser |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getTemplateParser() |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->templateParser; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param TemplateCompiler $templateCompiler |
|
280
|
|
|
* @return void |
|
281
|
|
|
*/ |
|
282
|
|
|
public function setTemplateCompiler(TemplateCompiler $templateCompiler) |
|
283
|
|
|
{ |
|
284
|
|
|
$this->templateCompiler = $templateCompiler; |
|
285
|
|
|
$this->templateCompiler->setRenderingContext($this); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @return TemplateCompiler |
|
290
|
|
|
*/ |
|
291
|
|
|
public function getTemplateCompiler() |
|
292
|
|
|
{ |
|
293
|
|
|
return $this->templateCompiler; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Delegation: Set the cache used by this View's compiler |
|
298
|
|
|
* |
|
299
|
|
|
* @param FluidCacheInterface $cache |
|
300
|
|
|
* @return void |
|
301
|
|
|
*/ |
|
302
|
|
|
public function setCache(FluidCacheInterface $cache) |
|
303
|
|
|
{ |
|
304
|
|
|
$this->cache = $cache; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @return FluidCacheInterface |
|
309
|
|
|
*/ |
|
310
|
|
|
public function getCache() |
|
311
|
|
|
{ |
|
312
|
|
|
return $this->cache; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* @return boolean |
|
317
|
|
|
*/ |
|
318
|
|
|
public function isCacheEnabled() |
|
319
|
|
|
{ |
|
320
|
|
|
return $this->cache instanceof FluidCacheInterface; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* Delegation: Set TemplateProcessor instances in the parser |
|
325
|
|
|
* through a public API. |
|
326
|
|
|
* |
|
327
|
|
|
* @param TemplateProcessorInterface[] $templateProcessors |
|
328
|
|
|
* @return void |
|
329
|
|
|
*/ |
|
330
|
|
|
public function setTemplateProcessors(array $templateProcessors) |
|
331
|
|
|
{ |
|
332
|
|
|
$this->templateProcessors = $templateProcessors; |
|
333
|
|
|
foreach ($this->templateProcessors as $templateProcessor) { |
|
334
|
|
|
$templateProcessor->setRenderingContext($this); |
|
335
|
|
|
} |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @return TemplateProcessorInterface[] |
|
340
|
|
|
*/ |
|
341
|
|
|
public function getTemplateProcessors() |
|
342
|
|
|
{ |
|
343
|
|
|
return $this->templateProcessors; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return string |
|
348
|
|
|
*/ |
|
349
|
|
|
public function getExpressionNodeTypes() |
|
350
|
|
|
{ |
|
351
|
|
|
return $this->expressionNodeTypes; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
/** |
|
355
|
|
|
* @param array $expressionNodeTypes |
|
356
|
|
|
* @return void |
|
357
|
|
|
*/ |
|
358
|
|
|
public function setExpressionNodeTypes(array $expressionNodeTypes) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->expressionNodeTypes = $expressionNodeTypes; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Build parser configuration |
|
365
|
|
|
* |
|
366
|
|
|
* @return Configuration |
|
367
|
|
|
*/ |
|
368
|
|
|
public function buildParserConfiguration() |
|
369
|
|
|
{ |
|
370
|
|
|
$parserConfiguration = new Configuration(); |
|
371
|
|
|
$escapeInterceptor = new Escape(); |
|
372
|
|
|
$parserConfiguration->addEscapingInterceptor($escapeInterceptor); |
|
373
|
|
|
return $parserConfiguration; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* @return string |
|
378
|
|
|
*/ |
|
379
|
|
|
public function getControllerName() |
|
380
|
|
|
{ |
|
381
|
|
|
return $this->controllerName; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* @param string $controllerName |
|
386
|
|
|
* @return void |
|
387
|
|
|
*/ |
|
388
|
|
|
public function setControllerName($controllerName) |
|
389
|
|
|
{ |
|
390
|
|
|
$this->controllerName = $controllerName; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* @return string |
|
395
|
|
|
*/ |
|
396
|
|
|
public function getControllerAction() |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->controllerAction; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* @param string $action |
|
403
|
|
|
* @return void |
|
404
|
|
|
*/ |
|
405
|
|
|
public function setControllerAction($action) |
|
406
|
|
|
{ |
|
407
|
|
|
$this->controllerAction = $action; |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
|