Skip to content

Commit

Permalink
chore: prevent generate unecessary temp file
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Jan 19, 2025
1 parent cca46ed commit 1b583d3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/Handler/FooterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private function getMetadata(): array {
}

private function getRenderedHtmlFooter(): string {
$tempFile = $this->tempManager->getTemporaryFile('footerTemplate.php');
file_put_contents($tempFile, $this->getTemplate());
$templates = new Engine($this->tempManager->getTempBaseDir());
return $templates->render(pathinfo($tempFile, PATHINFO_FILENAME), $this->getTemplateVars());
$templateFile = $this->getTemplateFile();
$pathInfo = pathinfo($templateFile);
$templates = new Engine($pathInfo['dirname']);
return $templates->render($pathInfo['filename'], $this->getTemplateVars());
}

public function setTemplateVar(string $name, mixed $value): self {
Expand Down Expand Up @@ -137,8 +137,14 @@ private function getTemplateVars(): array {
return $this->templateVars;
}

private function getTemplate(): string {
return $this->appConfig->getValueString(Application::APP_ID, 'footer_template', file_get_contents(__DIR__ . '/Templates/footer.php'));
private function getTemplateFile(): string {
$footerTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
if ($footerTemplate) {
$tempFile = $this->tempManager->getTemporaryFile('footerTemplate.php');
file_put_contents($tempFile, $footerTemplate);
return $tempFile;
}
return __DIR__ . '/Templates/footer.php';
}

private function getQrCodeImageBase64(string $text): string {
Expand Down

0 comments on commit 1b583d3

Please sign in to comment.