Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Wrap RecordCollection records in Laravel Collection

+8 -9
+8 -9
src/Data/RecordCollection.php
··· 3 3 namespace SocialDept\AtpClient\Data; 4 4 5 5 use Illuminate\Contracts\Support\Arrayable; 6 + use Illuminate\Support\Collection; 6 7 7 8 /** 8 9 * Collection wrapper for paginated AT Protocol records. ··· 13 14 class RecordCollection implements Arrayable 14 15 { 15 16 /** 16 - * @param array<Record<T>> $records 17 + * @param Collection<int, Record<T>> $records 17 18 */ 18 19 public function __construct( 19 - public readonly array $records, 20 + public readonly Collection $records, 20 21 public readonly ?string $cursor = null, 21 22 ) {} 22 23 ··· 29 30 public static function fromArray(array $data, callable $transformer): self 30 31 { 31 32 return new self( 32 - records: array_map( 33 - fn (array $record) => Record::fromArray($record, $transformer), 34 - $data['records'] ?? [] 33 + records: collect($data['records'] ?? [])->map( 34 + fn (array $record) => Record::fromArray($record, $transformer) 35 35 ), 36 36 cursor: $data['cursor'] ?? null, 37 37 ); ··· 43 43 public static function fromArrayRaw(array $data): self 44 44 { 45 45 return new self( 46 - records: array_map( 47 - fn (array $record) => Record::fromArrayRaw($record), 48 - $data['records'] ?? [] 46 + records: collect($data['records'] ?? [])->map( 47 + fn (array $record) => Record::fromArrayRaw($record) 49 48 ), 50 49 cursor: $data['cursor'] ?? null, 51 50 ); ··· 54 53 public function toArray(): array 55 54 { 56 55 return [ 57 - 'records' => array_map(fn (Record $r) => $r->toArray(), $this->records), 56 + 'records' => $this->records->map(fn (Record $r) => $r->toArray())->all(), 58 57 'cursor' => $this->cursor, 59 58 ]; 60 59 }