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,42 @@
<?php
namespace App\Framework\View\Processors;
use App\Framework\View\DomProcessor;
use App\Framework\View\RenderContext;
final readonly class PlaceholderReplacer implements DomProcessor
{
public function process(\DOMDocument $dom, RenderContext $context): void
{
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('//text()') as $textNode) {
$textNode->nodeValue = preg_replace_callback(
'/{{\s*([\w.]+)\s*}}/',
fn($m) => $this->resolveValue($context->data, $m[1]),
$textNode->nodeValue
);
}
}
private function resolveValue(array $data, string $expr): string
{
$keys = explode('.', $expr);
$value = $data;
foreach ($keys as $key) {
if (!is_array($value) || !array_key_exists($key, $value)) {
return "{{ $expr }}"; // Platzhalter bleibt erhalten
}
$value = $value[$key];
}
return is_scalar($value) ? (string)$value : '';
}
public function supports(\DOMElement $element): bool
{
return $element->tagName === 'text';
}
}