vid-queue/app/Data/InputData.php

43 lines
978 B
PHP
Raw Normal View History

2022-08-19 19:52:56 -05:00
<?php
namespace App\Data;
use App\Exceptions\Quit;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\Attributes\WithCast;
class InputData extends Data
{
#[DataCollectionOf(FileData::class)]
#[MapInputName('input')]
public DataCollection $files;
public ?string $url = null;
#[WithCast(Casts\Folder::class)]
public ?string $destination = null;
public ?string $title = null;
public bool $sync = false;
public function assertValid(): self
{
throw_if(
!$this->hasFiles() && !$this->hasURL(),
Quit::class,
'Must have either a valid file or URL'
);
return $this;
}
public function hasURL(): bool
{
return !empty($this->url);
}
public function hasFiles(): bool
{
return !empty($this->files) && !!$this->files->count();
}
}