ldc-boutique-cnc-sable/app/Actions/Slides/UpdateSlideInput.php

53 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace App\Actions\Slides;
use App\Contracts\ActionInput;
use App\Models\Slide;
use Domain\Models\ValueObjects\DatePeriod;
use Illuminate\Http\UploadedFile;
use Webmozart\Assert\Assert;
final readonly class UpdateSlideInput implements ActionInput
{
public function __construct(
public Slide $slide,
public string $title,
public ?string $text = null,
public UploadedFile | string | null $picture = null,
public ?string $pictureAlt = null,
public ?string $pictureTitle = null,
public ?string $link = null,
public ?string $linkLabel = null,
public bool $linkNewTab = false,
public bool $connected = false,
public DatePeriod $period = new DatePeriod(),
) {
Assert::stringNotEmpty(trim($this->title));
Assert::maxLength($this->title, 75);
Assert::true(
$this->picture !== null || ! empty($this->slide->picture) || ($this->text !== null && trim($this->text) !== ''),
'A slide must have either a picture or text.'
);
if ($this->pictureAlt !== null) {
Assert::maxLength($this->pictureAlt, 75);
}
if ($this->pictureTitle !== null) {
Assert::maxLength($this->pictureTitle, 75);
}
if ($this->link !== null) {
Assert::maxLength($this->link, 255);
}
if ($this->linkLabel !== null) {
Assert::maxLength($this->linkLabel, 255);
}
}
}