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