Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Registry | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| register | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withDefaults | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Field\Control; |
| 6 | |
| 7 | /** |
| 8 | * Maps named rich controls to the custom element that renders them. |
| 9 | * |
| 10 | * Registered names serialize as element descriptors, so the editor |
| 11 | * only ever interprets primitives, the structural controls (group, |
| 12 | * repeater, entries, blocks) and element. |
| 13 | * Later registrations win — a plugin may replace a built-in editor. |
| 14 | */ |
| 15 | final class Registry |
| 16 | { |
| 17 | /** @var array<string, array{tag: string, module: string}> */ |
| 18 | private array $entries = []; |
| 19 | |
| 20 | public function register(string $name, string $tag, string $module): void |
| 21 | { |
| 22 | $this->entries[$name] = [ |
| 23 | 'tag' => $tag, |
| 24 | 'module' => $module, |
| 25 | ]; |
| 26 | } |
| 27 | |
| 28 | public function has(string $name): bool |
| 29 | { |
| 30 | return isset($this->entries[$name]); |
| 31 | } |
| 32 | |
| 33 | /** @return array{tag: string, module: string} */ |
| 34 | public function get(string $name): array |
| 35 | { |
| 36 | return $this->entries[$name]; |
| 37 | } |
| 38 | |
| 39 | public static function withDefaults(): self |
| 40 | { |
| 41 | // Built-in rich controls move here stage by stage as they are |
| 42 | // converted to cosray-shipped custom elements. |
| 43 | $registry = new self(); |
| 44 | $registry->register('richtext', 'cosray-richtext', 'cosray:richtext'); |
| 45 | $registry->register('code', 'cosray-code', 'cosray:code'); |
| 46 | $registry->register('image', 'cosray-image', 'cosray:media'); |
| 47 | $registry->register('file', 'cosray-file', 'cosray:media'); |
| 48 | $registry->register('video', 'cosray-video', 'cosray:media'); |
| 49 | $registry->register('reference', 'cosray-reference', 'cosray:reference'); |
| 50 | |
| 51 | return $registry; |
| 52 | } |
| 53 | } |