Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3use SocialDept\AtpSchema\Data\LexiconDocument;
4use SocialDept\AtpSchema\Facades\Schema;
5
6if (! function_exists('schema')) {
7 /**
8 * Get the SchemaManager instance or load a schema.
9 *
10 * @return \SocialDept\AtpSchema\SchemaManager|LexiconDocument
11 */
12 function schema(?string $nsid = null)
13 {
14 if ($nsid === null) {
15 return app('schema');
16 }
17
18 return Schema::load($nsid);
19 }
20}
21
22if (! function_exists('schema_find')) {
23 /**
24 * Find a schema by NSID (nullable version).
25 */
26 function schema_find(string $nsid): ?LexiconDocument
27 {
28 return Schema::find($nsid);
29 }
30}
31
32if (! function_exists('schema_exists')) {
33 /**
34 * Check if a schema exists.
35 */
36 function schema_exists(string $nsid): bool
37 {
38 return Schema::exists($nsid);
39 }
40}
41
42if (! function_exists('schema_validate')) {
43 /**
44 * Validate data against a schema.
45 */
46 function schema_validate(string $nsid, array $data): bool
47 {
48 return Schema::validate($nsid, $data);
49 }
50}
51
52if (! function_exists('schema_generate')) {
53 /**
54 * Generate DTO code from a schema.
55 */
56 function schema_generate(string $nsid, ?string $outputPath = null): string
57 {
58 return Schema::generate($nsid, $outputPath);
59 }
60}