include missing
This commit is contained in:
parent
88b5850c32
commit
d3e12785bb
20 changed files with 584 additions and 4 deletions
40
src/Factories/CollectionFactory.php
Normal file
40
src/Factories/CollectionFactory.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Icefox\DTO\Factories;
|
||||
|
||||
use Icefox\DTO\Support\RuleFactory;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
use ReflectionParameter;
|
||||
use phpDocumentor\Reflection\PseudoTypes\Generic;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
|
||||
class CollectionFactory
|
||||
{
|
||||
/**
|
||||
* @return array<string,string|Rule[]>
|
||||
*/
|
||||
public static function rules(ReflectionParameter $parameter, ?Type $type): array
|
||||
{
|
||||
if (is_null($type)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!$type instanceof Generic) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$subtypes = $type->getTypes();
|
||||
|
||||
if (count($subtypes) == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$subtype = count($subtypes) == 1 ? $subtypes[0] : $subtypes[1];
|
||||
|
||||
return array_merge(
|
||||
['' => ['array']],
|
||||
RuleFactory::getRulesFromDocBlock($subtype, '.*'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue