Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Data\Types;
4
5use SocialDept\AtpSchema\Data\TypeDefinition;
6
7class UnknownType extends TypeDefinition
8{
9 /**
10 * Create a new UnknownType.
11 */
12 public function __construct(?string $description = null)
13 {
14 parent::__construct('unknown', $description);
15 }
16
17 /**
18 * Create from array data.
19 */
20 public static function fromArray(array $data): self
21 {
22 return new self(
23 description: $data['description'] ?? null
24 );
25 }
26
27 /**
28 * Convert to array.
29 */
30 public function toArray(): array
31 {
32 $array = ['type' => $this->type];
33
34 if ($this->description !== null) {
35 $array['description'] = $this->description;
36 }
37
38 return $array;
39 }
40
41 /**
42 * Validate a value against this type definition.
43 */
44 public function validate(mixed $value, string $path = ''): void
45 {
46 // Unknown type accepts any value
47 }
48}