1 | <?php |
||
24 | abstract class AbstractTemplateView extends AbstractView |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Constants defining possible rendering types |
||
29 | */ |
||
30 | const RENDERING_TEMPLATE = 1; |
||
31 | const RENDERING_PARTIAL = 2; |
||
32 | const RENDERING_LAYOUT = 3; |
||
33 | |||
34 | /** |
||
35 | * The initial rendering context for this template view. |
||
36 | * Due to the rendering stack, another rendering context might be active |
||
37 | * at certain points while rendering the template. |
||
38 | * |
||
39 | * @var RenderingContextInterface |
||
40 | */ |
||
41 | protected $baseRenderingContext; |
||
42 | |||
43 | /** |
||
44 | * Stack containing the current rendering type, the current rendering context, and the current parsed template |
||
45 | * Do not manipulate directly, instead use the methods"getCurrent*()", "startRendering(...)" and "stopRendering()" |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $renderingStack = []; |
||
50 | |||
51 | /** |
||
52 | * Constructor |
||
53 | * |
||
54 | * @param null|RenderingContextInterface $context |
||
55 | */ |
||
56 | public function __construct(RenderingContextInterface $context = null) |
||
65 | |||
66 | /** |
||
67 | * Initialize the RenderingContext. This method can be overridden in your |
||
68 | * View implementation to manipulate the rendering context *before* it is |
||
69 | * passed during rendering. |
||
70 | */ |
||
71 | public function initializeRenderingContext() |
||
75 | |||
76 | /** |
||
77 | * Sets the cache to use in RenderingContext. |
||
78 | * |
||
79 | * @param FluidCacheInterface $cache |
||
80 | * @return void |
||
81 | */ |
||
82 | public function setCache(FluidCacheInterface $cache) |
||
86 | |||
87 | /** |
||
88 | * Gets the TemplatePaths instance from RenderingContext |
||
89 | * |
||
90 | * @return TemplatePaths |
||
91 | */ |
||
92 | public function getTemplatePaths() |
||
96 | |||
97 | /** |
||
98 | * Gets the ViewHelperResolver instance from RenderingContext |
||
99 | * |
||
100 | * @return ViewHelperResolver |
||
101 | */ |
||
102 | public function getViewHelperResolver() |
||
106 | |||
107 | /** |
||
108 | * Gets the RenderingContext used by the View |
||
109 | * |
||
110 | * @return RenderingContextInterface |
||
111 | */ |
||
112 | public function getRenderingContext() |
||
116 | |||
117 | /** |
||
118 | * Injects a fresh rendering context |
||
119 | * |
||
120 | * @param RenderingContextInterface $renderingContext |
||
121 | * @return void |
||
122 | */ |
||
123 | public function setRenderingContext(RenderingContextInterface $renderingContext) |
||
128 | |||
129 | /** |
||
130 | * Assign a value to the variable container. |
||
131 | * |
||
132 | * @param string $key The key of a view variable to set |
||
133 | * @param mixed $value The value of the view variable |
||
134 | * @return $this |
||
135 | * @api |
||
136 | */ |
||
137 | public function assign($key, $value) |
||
142 | |||
143 | /** |
||
144 | * Assigns multiple values to the JSON output. |
||
145 | * However, only the key "value" is accepted. |
||
146 | * |
||
147 | * @param array $values Keys and values - only a value with key "value" is considered |
||
148 | * @return $this |
||
149 | * @api |
||
150 | */ |
||
151 | public function assignMultiple(array $values) |
||
159 | |||
160 | /** |
||
161 | * Loads the template source and render the template. |
||
162 | * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout. |
||
163 | * |
||
164 | * @param string|null $actionName If set, this action's template will be rendered instead of the one defined in the context. |
||
165 | * @return string Rendered Template |
||
166 | * @api |
||
167 | */ |
||
168 | public function render($actionName = null) |
||
206 | |||
207 | /** |
||
208 | * Renders a given section. |
||
209 | * |
||
210 | * @param string $sectionName Name of section to render |
||
211 | * @param array $variables The variables to use |
||
212 | * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string |
||
213 | * @return string rendered template for the section |
||
214 | * @throws InvalidSectionException |
||
215 | */ |
||
216 | public function renderSection($sectionName, array $variables = [], $ignoreUnknown = false) |
||
271 | |||
272 | /** |
||
273 | * Renders a partial. |
||
274 | * |
||
275 | * @param string $partialName |
||
276 | * @param string $sectionName |
||
277 | * @param array $variables |
||
278 | * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string |
||
279 | * @return string |
||
280 | */ |
||
281 | public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = false) |
||
305 | |||
306 | /** |
||
307 | * Start a new nested rendering. Pushes the given information onto the $renderingStack. |
||
308 | * |
||
309 | * @param integer $type one of the RENDERING_* constants |
||
310 | * @param ParsedTemplateInterface $template |
||
311 | * @param RenderingContextInterface $context |
||
312 | * @return void |
||
313 | */ |
||
314 | protected function startRendering($type, ParsedTemplateInterface $template, RenderingContextInterface $context) |
||
318 | |||
319 | /** |
||
320 | * Stops the current rendering. Removes one element from the $renderingStack. Make sure to always call this |
||
321 | * method pair-wise with startRendering(). |
||
322 | * |
||
323 | * @return void |
||
324 | */ |
||
325 | protected function stopRendering() |
||
329 | |||
330 | /** |
||
331 | * Get the current rendering type. |
||
332 | * |
||
333 | * @return integer one of RENDERING_* constants |
||
334 | */ |
||
335 | protected function getCurrentRenderingType() |
||
340 | |||
341 | /** |
||
342 | * Get the parsed template which is currently being rendered or compiled. |
||
343 | * |
||
344 | * @return ParsedTemplateInterface |
||
345 | */ |
||
346 | protected function getCurrentParsedTemplate() |
||
370 | |||
371 | /** |
||
372 | * Get the rendering context which is currently used. |
||
373 | * |
||
374 | * @return RenderingContextInterface |
||
375 | */ |
||
376 | protected function getCurrentRenderingContext() |
||
381 | } |
||
382 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: