Final Class Yiisoft\FormModel\NonArrayTypeCaster
| Inheritance | Yiisoft\FormModel\NonArrayTypeCaster |
|---|---|
| Implements | Yiisoft\Hydrator\TypeCaster\TypeCasterInterface |
Ensures that non-array value for property of array type is converted to an empty array.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| cast() | Yiisoft\FormModel\NonArrayTypeCaster |
Method Details
| public \Yiisoft\Hydrator\Result cast ( mixed $value, \Yiisoft\Hydrator\TypeCaster\TypeCastContext $context ) | ||
| $value | mixed | |
| $context | \Yiisoft\Hydrator\TypeCaster\TypeCastContext | |
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();
}
Signup or Login in order to comment.