Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Parser;
4
5use SocialDept\AtpSchema\Contracts\LexiconRegistry;
6use SocialDept\AtpSchema\Data\LexiconDocument;
7
8class InMemoryLexiconRegistry implements LexiconRegistry
9{
10 /**
11 * Registered lexicon documents.
12 *
13 * @var array<string, LexiconDocument>
14 */
15 protected array $documents = [];
16
17 /**
18 * Register a lexicon document.
19 */
20 public function register(LexiconDocument $document): void
21 {
22 $this->documents[$document->getNsid()] = $document;
23 }
24
25 /**
26 * Get a lexicon document by NSID.
27 */
28 public function get(string $nsid): ?LexiconDocument
29 {
30 return $this->documents[$nsid] ?? null;
31 }
32
33 /**
34 * Check if a lexicon document exists.
35 */
36 public function has(string $nsid): bool
37 {
38 return isset($this->documents[$nsid]);
39 }
40
41 /**
42 * Get all registered lexicon documents.
43 *
44 * @return array<string, LexiconDocument>
45 */
46 public function all(): array
47 {
48 return $this->documents;
49 }
50
51 /**
52 * Clear all registered lexicon documents.
53 */
54 public function clear(): void
55 {
56 $this->documents = [];
57 }
58}