42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
|
|
<?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;
|
||
|
|
}
|
||
|
|
}
|