@@ -93,11 +93,11 @@ class Parser extends View
9393 /**
9494 * Constructor
9595 *
96- * @param \Config\View $config
97- * @param string $viewPath
98- * @param mixed $loader
99- * @param boolean $debug
100- * @param LoggerInterface $logger
96+ * @param \Config\View $config
97+ * @param string $viewPath
98+ * @param mixed $loader
99+ * @param boolean $debug
100+ * @param LoggerInterface $logger
101101 */
102102 public function __construct ($ config , string $ viewPath = null , $ loader = null , bool $ debug = null , LoggerInterface $ logger = null )
103103 {
@@ -157,20 +157,25 @@ public function render(string $view, array $options = null, bool $saveData = nul
157157 throw ViewException::forInvalidFile ($ file );
158158 }
159159
160+ if (is_null ($ this ->tempData ))
161+ {
162+ $ this ->tempData = $ this ->data ;
163+ }
164+
160165 $ template = file_get_contents ($ file );
161- $ output = $ this ->parse ($ template , $ this ->data , $ options );
166+ $ output = $ this ->parse ($ template , $ this ->tempData , $ options );
162167 $ this ->logPerformance ($ start , microtime (true ), $ view );
163168
164- if (! $ saveData )
169+ if ($ saveData )
165170 {
166- $ this ->data = [] ;
171+ $ this ->data = $ this -> tempData ;
167172 }
168173 // Should we cache?
169174 if (isset ($ options ['cache ' ]))
170175 {
171176 cache ()->save ($ cacheName , $ output , (int ) $ options ['cache ' ]);
172177 }
173-
178+ $ this -> tempData = null ;
174179 return $ output ;
175180 }
176181
@@ -196,14 +201,22 @@ public function renderString(string $template, array $options = null, bool $save
196201 $ saveData = $ this ->config ->saveData ;
197202 }
198203
199- $ output = $ this ->parse ($ template , $ this ->data , $ options );
204+ if (is_null ($ this ->tempData ))
205+ {
206+ $ this ->tempData = $ this ->data ;
207+ }
208+
209+ $ output = $ this ->parse ($ template , $ this ->tempData , $ options );
200210
201211 $ this ->logPerformance ($ start , microtime (true ), $ this ->excerpt ($ template ));
202212
203- if (! $ saveData )
213+ if ($ saveData )
204214 {
205- $ this ->data = [] ;
215+ $ this ->data = $ this -> tempData ;
206216 }
217+
218+ $ this ->tempData = null ;
219+
207220 return $ output ;
208221 }
209222
@@ -243,7 +256,8 @@ public function setData(array $data = [], string $context = null): RendererInter
243256 }
244257 }
245258
246- $ this ->data = array_merge ($ this ->data , $ data );
259+ $ this ->tempData = $ this ->tempData ?? $ this ->data ;
260+ $ this ->tempData = array_merge ($ this ->tempData , $ data );
247261
248262 return $ this ;
249263 }
@@ -532,7 +546,14 @@ protected function parseConditionals(string $template): string
532546
533547 // Parse the PHP itself, or insert an error so they can debug
534548 ob_start ();
535- extract ($ this ->data );
549+
550+ if (is_null ($ this ->tempData ))
551+ {
552+ $ this ->tempData = $ this ->data ;
553+ }
554+
555+ extract ($ this ->tempData );
556+
536557 try
537558 {
538559 eval ('?> ' . $ template . '<?php ' );
@@ -542,6 +563,7 @@ protected function parseConditionals(string $template): string
542563 ob_end_clean ();
543564 throw ViewException::forTagSyntaxError (str_replace (['?> ' , '<?php ' ], '' , $ template ));
544565 }
566+
545567 return ob_get_clean ();
546568 }
547569
0 commit comments