Final Class Yiisoft\Hydrator\TypeCaster\CompositeTypeCaster
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Allows using many type casters one by one before the value cast successfully.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| cast() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $typeCasters | Yiisoft\ |
Type casters to use. |
public function __construct(
TypeCasterInterface ...$typeCasters,
) {
$this->typeCasters = $typeCasters;
}
| public Yiisoft\ | ||
| $value | mixed | |
| $context | Yiisoft\ |
|
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();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.