chore: lots of changes

This commit is contained in:
2025-05-24 07:09:22 +02:00
parent 77ee769d5e
commit 899227b0a4
178 changed files with 5145 additions and 53 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Framework\View;
final class ComponentRenderer
{
public function __construct(
private readonly TemplateLoader $loader = new TemplateLoader(),
private readonly Compiler $compiler = new Compiler(),
private readonly TemplateProcessor $processor = new TemplateProcessor(),
private string $cacheDir = __DIR__ . "/cache/components/"
) {}
public function render(string $componentName, array $data): string
{
$path = $this->loader->getComponentPath($componentName);
if (!file_exists($path)) {
return "<!-- Komponente '$componentName' nicht gefunden -->";
}
# Cache prüfen
$hash = md5_file($path) . '_' . md5(serialize($data));
$cacheFile = $this->cacheDir . "/{$componentName}_{$hash}.html";;
if(file_exists($cacheFile)) {
return file_get_contents($cacheFile);
}
$template = file_get_contents($path);
$compiled = $this->compiler->compile($template)->saveHTML();
$context = new RenderContext(
template: $componentName,
data: $data
);
$output = $this->processor->render($context, $compiled);
if(!is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0777, true);
}
file_put_contents($cacheFile, $output);
return $output;
}
}