(#3) - templating
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user