Skip to content

Commit

Permalink
The View class. Optimizing duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
iRedds committed Dec 11, 2021
1 parent d42da43 commit 544e0c1
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
}

// Make our view data available to the view.
$this->tempData = $this->tempData ?? $this->data;

if ($saveData) {
$this->data = $this->tempData;
}
$this->prepareTemplateData($saveData);

// Save current vars
$renderVars = $this->renderVars;
Expand Down Expand Up @@ -275,13 +271,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
*/
public function renderString(string $view, ?array $options = null, ?bool $saveData = null): string
{
$start = microtime(true);
$saveData = $saveData ?? $this->saveData;
$this->tempData = $this->tempData ?? $this->data;

if ($saveData) {
$this->data = $this->tempData;
}
$start = microtime(true);
$saveData = $saveData ?? $this->saveData;
$this->prepareTemplateData($saveData);

$output = (function (string $view): string {
extract($this->tempData);
Expand Down Expand Up @@ -454,4 +446,13 @@ protected function logPerformance(float $start, float $end, string $view)
];
}
}

protected function prepareTemplateData(bool $saveData): void
{
$this->tempData = $this->tempData ?? $this->data;

if ($saveData) {
$this->data = $this->tempData;
}
}
}

0 comments on commit 544e0c1

Please sign in to comment.