Final Class Yiisoft\Hydrator\TypeCaster\EnumTypeCaster
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Casts values to enumerations.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| cast() | Yiisoft\ |
Method Details
| public Yiisoft\ | ||
| $value | mixed | |
| $context | Yiisoft\ |
|
public function cast(mixed $value, TypeCastContext $context): Result
{
$type = $context->getReflectionType();
if ($type instanceof ReflectionNamedType) {
return $this->castInternal($value, $type);
}
if (!$type instanceof ReflectionUnionType) {
return Result::fail();
}
foreach ($type->getTypes() as $t) {
if (!$t instanceof ReflectionNamedType) {
continue;
}
$result = $this->castInternal($value, $t);
if ($result->isResolved()) {
return $result;
}
}
return Result::fail();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.