(#3) - templating

This commit is contained in:
Martin Slachta
2026-06-14 07:16:13 +02:00
parent 37bced77f4
commit 7b3d9f0ece
32 changed files with 870 additions and 126 deletions
@@ -0,0 +1,41 @@
<?php
namespace Reservair\Templating;
/** Holds the mapping from custom element tag names to their handlers. */
class RsvTemplateRegistry {
/** @var array<string, RsvTemplateElement> */
private array $elements = [];
public function register(string $tag, RsvTemplateElement $element): void {
$this->elements[$tag] = $element;
}
public function get(string $tag): ?RsvTemplateElement {
return $this->elements[$tag] ?? null;
}
/** @return array<string, RsvTemplateElement> */
public function all(): array {
return $this->elements;
}
/**
* Extends a wp_kses allowlist so the registered custom elements survive
* sanitization of admin HTML. Each element contributes its tag and the
* attributes it declares via symbols().
*
* @param array<string, mixed> $base A wp_kses allowed-html map to extend.
* @return array<string, mixed>
*/
public function kses_allowed(array $base = []): array {
foreach ($this->elements as $tag => $element) {
$attributes = [];
foreach ($element->symbols() as $name) {
$attributes[$name] = true;
}
$base[$tag] = $attributes;
}
return $base;
}
}