2022-11-17 21:47:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Contribution;
|
|
|
|
|
|
|
|
use App\Contribution\Documents\ContributionDocument;
|
|
|
|
use App\Contribution\Documents\DvDocument;
|
2022-11-17 22:59:16 +01:00
|
|
|
use App\Contribution\Documents\RemscheidDocument;
|
2022-11-17 21:47:45 +01:00
|
|
|
use App\Contribution\Documents\SolingenDocument;
|
2023-03-14 22:29:39 +01:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Validation\Rule;
|
2022-11-17 21:47:45 +01:00
|
|
|
|
|
|
|
class ContributionFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array<int, class-string<ContributionDocument>>
|
|
|
|
*/
|
|
|
|
private array $documents = [
|
|
|
|
DvDocument::class,
|
|
|
|
SolingenDocument::class,
|
2022-11-17 22:59:16 +01:00
|
|
|
RemscheidDocument::class,
|
2022-11-17 21:47:45 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2023-03-14 22:29:39 +01:00
|
|
|
* @return Collection<int, array{title: mixed, class: mixed}>
|
2022-11-17 21:47:45 +01:00
|
|
|
*/
|
2023-03-14 22:29:39 +01:00
|
|
|
public function compilerSelect(): Collection
|
2022-11-17 21:47:45 +01:00
|
|
|
{
|
|
|
|
return collect($this->documents)->map(fn ($document) => [
|
|
|
|
'title' => $document::getName(),
|
|
|
|
'class' => $document,
|
2023-03-14 22:29:39 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function typeRule(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => ['required', Rule::in($this->documents)],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param class-string<ContributionDocument> $type
|
|
|
|
*
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function rules(string $type): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...$type::globalRules(),
|
|
|
|
...$type::rules(),
|
|
|
|
];
|
2022-11-17 21:47:45 +01:00
|
|
|
}
|
|
|
|
}
|