Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Generated\App\Bsky\Graph\Defs;
4
5use Carbon\Carbon;
6use SocialDept\AtpSchema\Data\Data;
7use SocialDept\AtpSchema\Generated\Com\Atproto\Label\Defs\Label;
8
9/**
10 * GENERATED CODE - DO NOT EDIT
11 *
12 * Lexicon: app.bsky.graph.defs.listViewBasic
13 * Type: object
14 *
15 * @property string $uri
16 * @property string $cid
17 * @property string $name
18 * @property mixed $purpose
19 * @property string|null $avatar
20 * @property int|null $listItemCount
21 * @property array<Label>|null $labels
22 * @property mixed $viewer
23 * @property Carbon|null $indexedAt
24 *
25 * Constraints:
26 * - Required: uri, cid, name, purpose
27 * - uri: Format: at-uri
28 * - cid: Format: cid
29 * - name: Max length: 64
30 * - name: Min length: 1
31 * - avatar: Format: uri
32 * - listItemCount: Minimum: 0
33 * - indexedAt: Format: datetime
34 */
35class ListViewBasic extends Data
36{
37 public function __construct(
38 public readonly string $uri,
39 public readonly string $cid,
40 public readonly string $name,
41 public readonly mixed $purpose,
42 public readonly ?string $avatar = null,
43 public readonly ?int $listItemCount = null,
44 public readonly ?array $labels = null,
45 public readonly mixed $viewer = null,
46 public readonly ?Carbon $indexedAt = null
47 ) {
48 }
49
50 /**
51 * Get the lexicon NSID for this data type.
52 *
53 * @return string
54 */
55 public static function getLexicon(): string
56 {
57 return 'app.bsky.graph.defs.listViewBasic';
58 }
59
60
61 /**
62 * Create an instance from an array.
63 *
64 * @param array $data The data array
65 * @return static
66 */
67 public static function fromArray(array $data): static
68 {
69 return new static(
70 uri: $data['uri'],
71 cid: $data['cid'],
72 name: $data['name'],
73 purpose: $data['purpose'],
74 avatar: $data['avatar'] ?? null,
75 listItemCount: $data['listItemCount'] ?? null,
76 labels: isset($data['labels']) ? array_map(fn ($item) => Label::fromArray($item), $data['labels']) : [],
77 viewer: $data['viewer'] ?? null,
78 indexedAt: isset($data['indexedAt']) ? Carbon::parse($data['indexedAt']) : null
79 );
80 }
81
82}