Simplified fix thanks to @vlakoff (https://github.com/vlakoff)

pull/581/head
fadrian06 8 months ago
parent 276a9e69f3
commit f3453cab17

@ -116,19 +116,17 @@ class View
throw new \Exception("Template file not found: {$normalized_path}."); throw new \Exception("Template file not found: {$normalized_path}.");
} }
if (\is_array($data)) {
$this->vars = \array_merge($this->vars, $data);
}
\extract($this->vars); \extract($this->vars);
include $this->template; if (\is_array($data)) {
\extract($data);
if ($this->preserveVars === false && $data !== null) { if ($this->preserveVars) {
foreach (array_keys($data) as $variable) { $this->vars = \array_merge($this->vars, $data);
unset($this->vars[$variable]);
} }
} }
include $this->template;
} }
/** /**

@ -191,6 +191,22 @@ class ViewTest extends TestCase
$this->view->render('input'); $this->view->render('input');
} }
public function testKeepThePreviousStateOfDataSettedBySetMethod(): void
{
$this->view->preserveVars = false;
$this->view->set('prop', 'bar');
$this->expectOutputString(<<<html
<div>qux</div>
<div>bar</div>
html);
$this->view->render('myComponent', ['prop' => 'qux']);
$this->view->render('myComponent');
}
public static function renderDataProvider(): array public static function renderDataProvider(): array
{ {
return [ return [

Loading…
Cancel
Save