HitsDTO.php 482 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App\DTO\Search;
  3. class HitsDTO
  4. {
  5. /**
  6. * @param HitItemDTO[] $items
  7. */
  8. public function __construct(
  9. public int $total,
  10. public array $items,
  11. ) {}
  12. public static function fromArray(array $data): self
  13. {
  14. return new self(
  15. total: $data['total']['value'],
  16. items: array_map(
  17. fn($item) => HitItemDTO::fromArray($item),
  18. $data['hits']
  19. )
  20. );
  21. }
  22. }