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,41 @@
<?php
namespace App\Framework\View\Processors;
use App\Framework\View\DomProcessor;
use App\Framework\View\DomTemplateParser;
use App\Framework\View\RenderContext;
use App\Framework\View\TemplateLoader;
final readonly class IncludeProcessor implements DomProcessor
{
public function __construct(
private TemplateLoader $loader,
private DomTemplateParser $parser = new DomTemplateParser()
) {}
public function process(\DOMDocument $dom, RenderContext $context): void
{
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('//include[@file]') as $includeNode) {
$file = $includeNode->getAttribute('file');
try {
$html = $this->loader->load($file);
$includedDom = $this->parser->parse($html);
$fragment = $dom->createDocumentFragment();
foreach ($includedDom->documentElement->childNodes as $child) {
$fragment->appendChild($dom->importNode($child, true));
}
$includeNode->parentNode?->replaceChild($fragment, $includeNode);
} catch (\Throwable $e) {
// Optional: Fehlerkommentar ins Template schreiben
$error = $dom->createComment("Fehler beim Laden von '$file': " . $e->getMessage());
$includeNode->parentNode?->replaceChild($error, $includeNode);
}
}
}
}