chore: lots of changes
This commit is contained in:
42
src/Framework/View/Processors/SlotProcessor.php
Normal file
42
src/Framework/View/Processors/SlotProcessor.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Framework\View\Processors;
|
||||
|
||||
use App\Framework\View\DomProcessor;
|
||||
use App\Framework\View\RenderContext;
|
||||
|
||||
/*
|
||||
|
||||
<component name="card">
|
||||
<slot name="header">Default Header</slot>
|
||||
<slot>Main Content</slot>
|
||||
</component>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
final readonly class SlotProcessor implements DomProcessor
|
||||
{
|
||||
public function process(\DOMDocument $dom, RenderContext $context): void
|
||||
{
|
||||
$xpath = new \DOMXPath($dom);
|
||||
|
||||
foreach ($xpath->query('//slot[@name]') as $slotNode) {
|
||||
$slotName = $slotNode->getAttribute('name');
|
||||
$html = $context->slots[$slotName] ?? null;
|
||||
|
||||
$replacement = $dom->createDocumentFragment();
|
||||
|
||||
if ($html !== null) {
|
||||
@$replacement->appendXML($html);
|
||||
} else {
|
||||
// Fallback-Inhalt erhalten (die inneren Nodes des slot-Tags)
|
||||
foreach ($slotNode->childNodes as $child) {
|
||||
$replacement->appendChild($child->cloneNode(true));
|
||||
}
|
||||
}
|
||||
|
||||
$slotNode->parentNode?->replaceChild($replacement, $slotNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user