Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Data\Responses\Bsky\Graph;
4
5use Illuminate\Contracts\Support\Arrayable;
6use Illuminate\Support\Collection;
7use SocialDept\AtpSchema\Generated\App\Bsky\Graph\Defs\ListItemView;
8use SocialDept\AtpSchema\Generated\App\Bsky\Graph\Defs\ListView;
9
10/**
11 * @implements Arrayable<string, mixed>
12 */
13class GetListResponse implements Arrayable
14{
15 /**
16 * @param Collection<int, ListItemView> $items
17 */
18 public function __construct(
19 public readonly ListView $list,
20 public readonly Collection $items,
21 public readonly ?string $cursor = null,
22 ) {}
23
24 public static function fromArray(array $data): self
25 {
26 return new self(
27 list: ListView::fromArray($data['list']),
28 items: collect($data['items'] ?? [])->map(
29 fn (array $item) => ListItemView::fromArray($item)
30 ),
31 cursor: $data['cursor'] ?? null,
32 );
33 }
34
35 public function toArray(): array
36 {
37 return [
38 'list' => $this->list->toArray(),
39 'items' => $this->items->map(fn (ListItemView $i) => $i->toArray())->all(),
40 'cursor' => $this->cursor,
41 ];
42 }
43}