public function cast(mixed $value, TypeCastContext $context): Result
{
$type = $context->getReflectionType();
$hydrator = $context->getHydrator();
if (!is_array($value)) {
return Result::fail();
}
if ($type instanceof ReflectionNamedType) {
return $this->castInternal($value, $type, $hydrator);
}
if (!$type instanceof ReflectionUnionType) {
return Result::fail();
}
foreach ($type->getTypes() as $t) {
if (!$t instanceof ReflectionNamedType) {
continue;
}
$result = $this->castInternal($value, $t, $hydrator);
if ($result->isResolved()) {
return $result;
}
}
return Result::fail();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.