This commit is contained in:
icefox 2026-02-23 21:35:08 -03:00
parent 367858c97c
commit 6b1a385292
No known key found for this signature in database
13 changed files with 191 additions and 80 deletions

38
src/CustomHandlers.php Normal file
View file

@ -0,0 +1,38 @@
<?php
namespace Icefox\DTO;
use Icefox\DTO\RuleFactory;
use phpDocumentor\Reflection\PseudoTypes\Generic;
class CustomHandlers
{
/**
* @return array<string,string[]>
*/
public static function CollectionRules(ParameterMeta $parameter, RuleFactory $factory): array
{
if (is_null($parameter->tag)) {
return [];
}
$type = $parameter->tag->getType();
if (!$type instanceof Generic) {
return [];
}
$subtypes = $type->getTypes();
if (count($subtypes) == 0) {
return ['' => ['array']];
}
$subtype = count($subtypes) == 1 ? $subtypes[0] : $subtypes[1];
return $factory->mergeRules(
['' => ['array']],
$factory->getRulesFromDocBlock($subtype, '.*'),
);
}
}