Parse and validate AT Protocol Lexicons with DTO generation for Laravel

Add fromJson() and getVersion() methods to LexiconDocument

Changed files
+26
src
+26
src/Data/LexiconDocument.php
··· 93 93 } 94 94 95 95 /** 96 + * Create from JSON string. 97 + */ 98 + public static function fromJson(string $json, ?string $source = null): self 99 + { 100 + $data = json_decode($json, true); 101 + 102 + if (json_last_error() !== JSON_ERROR_NONE) { 103 + throw new \InvalidArgumentException('Invalid JSON: '.json_last_error_msg()); 104 + } 105 + 106 + if (! is_array($data)) { 107 + throw new \InvalidArgumentException('JSON must decode to an array'); 108 + } 109 + 110 + return self::fromArray($data, $source); 111 + } 112 + 113 + /** 96 114 * Get a definition by name. 97 115 */ 98 116 public function getDefinition(string $name): ?array ··· 132 150 public function getNsid(): string 133 151 { 134 152 return $this->id->toString(); 153 + } 154 + 155 + /** 156 + * Get lexicon version. 157 + */ 158 + public function getVersion(): int 159 + { 160 + return $this->lexicon; 135 161 } 136 162 137 163 /**