38 lines
830 B
PHP
38 lines
830 B
PHP
<?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, '.*'),
|
|
);
|
|
}
|
|
}
|
|
|