0 follower

Final Class Yiisoft\FormModel\NonArrayTypeCaster

InheritanceYiisoft\FormModel\NonArrayTypeCaster
ImplementsYiisoft\Hydrator\TypeCaster\TypeCasterInterface

Ensures that non-array value for property of array type is converted to an empty array.

Public Methods

Hide inherited methods

Method Description Defined By
cast() Yiisoft\FormModel\NonArrayTypeCaster

Method Details

Hide inherited methods

cast() public method

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();
}