64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
final readonly class HeroSlideData
|
|
{
|
|
public function __construct(
|
|
public string $title,
|
|
public ?string $label = null,
|
|
public ?string $description = null,
|
|
public string $mediaType = 'image',
|
|
public ?string $image = null,
|
|
public ?string $videoUrl = null,
|
|
public ?string $mobileVideoUrl = null,
|
|
public ?string $mobileImage = null,
|
|
public ?string $buttonText = null,
|
|
public ?string $buttonUrl = null,
|
|
public int $orderIndex = 0,
|
|
public bool $isActive = true,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
title: $data['title'],
|
|
label: $data['label'] ?? null,
|
|
description: $data['description'] ?? null,
|
|
mediaType: $data['media_type'] ?? 'image',
|
|
image: $data['image'] ?? null,
|
|
videoUrl: $data['video_url'] ?? null,
|
|
mobileVideoUrl: $data['mobile_video_url'] ?? null,
|
|
mobileImage: $data['mobile_image'] ?? null,
|
|
buttonText: $data['button_text'] ?? null,
|
|
buttonUrl: $data['button_url'] ?? null,
|
|
orderIndex: $data['order_index'] ?? 0,
|
|
isActive: $data['is_active'] ?? true,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'label' => $this->label,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'media_type' => $this->mediaType,
|
|
'image' => $this->image,
|
|
'video_url' => $this->videoUrl,
|
|
'mobile_video_url' => $this->mobileVideoUrl,
|
|
'mobile_image' => $this->mobileImage,
|
|
'button_text' => $this->buttonText,
|
|
'button_url' => $this->buttonUrl,
|
|
'order_index' => $this->orderIndex,
|
|
'is_active' => $this->isActive,
|
|
];
|
|
}
|
|
}
|