diff --git a/flight/template/View.php b/flight/template/View.php index 9397cc6..f78a968 100644 --- a/flight/template/View.php +++ b/flight/template/View.php @@ -20,6 +20,8 @@ class View /** File extension. */ public string $extension = '.php'; + public bool $preserveVars = true; + /** * View variables. * @@ -122,7 +124,7 @@ class View include $this->template; - if ($data !== null) { + if ($this->preserveVars === false && $data !== null) { foreach (array_keys($data) as $variable) { unset($this->vars[$variable]); } diff --git a/tests/FlightTest.php b/tests/FlightTest.php index fe5b144..f9f2855 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -22,6 +22,7 @@ class FlightTest extends TestCase $_REQUEST = []; Flight::init(); Flight::setEngine(new Engine()); + Flight::set('flight.views.path', __DIR__ . '/views'); } protected function tearDown(): void @@ -355,9 +356,9 @@ class FlightTest extends TestCase $this->expectOutputString('Thisisaroutewithhtml'); } - public function testItDoesNotKeepThePreviousStateOfOneViewComponentUsingFlightRender(): void + public function testDoesNotPreserveVarsWhenFlagIsDisabled(): void { - Flight::set('flight.views.path', __DIR__ . '/views'); + Flight::view()->preserveVars = false; $this->expectOutputString("