Final Class Yiisoft\Hydrator\TypeCaster\NullTypeCaster
| Inheritance | Yiisoft\Hydrator\TypeCaster\NullTypeCaster |
|---|---|
| Implements | Yiisoft\Hydrator\TypeCaster\TypeCasterInterface |
Configurable type caster for casting value to null.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Hydrator\TypeCaster\NullTypeCaster | |
| cast() | Yiisoft\Hydrator\TypeCaster\NullTypeCaster |
Method Details
| public mixed __construct ( boolean $null = true, boolean $emptyString = false, boolean $emptyArray = false ) | ||
| $null | boolean | |
| $emptyString | boolean | |
| $emptyArray | boolean | |
public function __construct(
private bool $null = true,
private bool $emptyString = false,
private bool $emptyArray = false,
) {
}
| 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 (!$this->isAllowNull($context->getReflectionType())) {
return Result::fail();
}
if (
($this->null && $value === null)
|| ($this->emptyString && $value === '')
|| ($this->emptyArray && $value === [])
) {
return Result::success(null);
}
return Result::fail();
}
Signup or Login in order to comment.