Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Exceptions;
4
5class SchemaValidationException extends SchemaException
6{
7 /**
8 * Create exception for invalid schema structure.
9 */
10 public static function invalidStructure(string $nsid, array $errors): self
11 {
12 $message = "Schema validation failed for {$nsid}:\n".implode("\n", $errors);
13
14 return static::withContext($message, [
15 'nsid' => $nsid,
16 'errors' => $errors,
17 ]);
18 }
19
20 /**
21 * Create exception for missing required field.
22 */
23 public static function missingField(string $nsid, string $field): self
24 {
25 return static::withContext(
26 "Required field missing in schema {$nsid}: {$field}",
27 ['nsid' => $nsid, 'field' => $field]
28 );
29 }
30
31 /**
32 * Create exception for invalid lexicon version.
33 */
34 public static function invalidVersion(string $nsid, int $version): self
35 {
36 return static::withContext(
37 "Unsupported lexicon version {$version} in schema {$nsid}",
38 ['nsid' => $nsid, 'version' => $version]
39 );
40 }
41}