0 follower

Final Class Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster

InheritanceYiisoft\Hydrator\TypeCaster\CompositeTypeCaster
ImplementsYiisoft\Hydrator\TypeCaster\TypeCasterInterface

Allows using many type casters one by one before the value cast successfully.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Hydrator\TypeCaster\TypeCasterInterface $typeCasters )
$typeCasters Yiisoft\Hydrator\TypeCaster\TypeCasterInterface

Type casters to use.

                public function __construct(
    TypeCasterInterface ...$typeCasters
) {
    $this->typeCasters = $typeCasters;
}

            
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
{
    foreach ($this->typeCasters as $typeCaster) {
        $result = $typeCaster->cast($value, $context);
        if ($result->isResolved()) {
            return $result;
        }
    }
    return Result::fail();
}