Final Class Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster
| Inheritance | Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster |
|---|---|
| Implements | Yiisoft\Hydrator\TypeCaster\TypeCasterInterface |
Allows using many type casters one by one before the value cast successfully.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster | |
| cast() | Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster |
Method Details
| 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;
}
| 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();
}
Signup or Login in order to comment.