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}.");
}
if (\is_array($data)) {
$this->vars = \array_merge($this->vars, $data);
}
\extract($this->vars);
include $this->template;
if (\is_array($data)) {
\extract($data);
if ($this->preserveVars === false && $data !== null) {
foreach (array_keys($data) as $variable) {
unset($this->vars[$variable]);
if ($this->preserveVars) {
$this->vars = \array_merge($this->vars, $data);
}
}
include $this->template;
}
/**

@ -191,6 +191,22 @@ class ViewTest extends TestCase
$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
{
return [

Loading…
Cancel
Save