Final Class Yiisoft\FormModel\NonArrayTypeCaster
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Ensures that non-array value for property of array type is converted to an empty array.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| cast() | Yiisoft\ |
Method Details
| public \ | ||
| $value | mixed | |
| $context | \ |
|
public function cast(mixed $value, TypeCastContext $context): Result
{
if (is_array($value)) {
return Result::fail();
}
if ($this->isArray($context->getReflectionType())) {
return Result::success([]);
}
return Result::fail();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.