0 follower

Final Class Yiisoft\Validator\EmptyCondition\WhenNull

InheritanceYiisoft\Validator\EmptyCondition\WhenNull

Empty condition is a callable returning true if a value must be considered empty.

With WhenNull a rule is considered empty only when the value is null or the property is missing. With regard to validation process, a corresponding rule is skipped only if this condition is met and WhenNull is set:

  • At a rule level via $skipOnEmpty property, but only for rules implementing {@see \Yiisoft\Validator\EmptyCondition\SkipOnEmptyTrait} / including {@see \Yiisoft\Validator\EmptyCondition\SkipOnEmptyTrait}.
  • At validator level ({@see \Yiisoft\Validator\EmptyCondition\Validator::$defaultSkipOnEmptyCondition}).

There is no shortcut for this condition, because it's considered less used. Use new instance directly: new WhenNull().

Public Methods

Hide inherited methods

Method Description Defined By
__invoke() Yiisoft\Validator\EmptyCondition\WhenNull

Method Details

Hide inherited methods

__invoke() public method

public boolean __invoke ( mixed $value, boolean $isPropertyMissing false )
$value mixed

The validated value.

$isPropertyMissing boolean

A flag defining whether the property is missing (not used / not passed at all).

return boolean

Whether the validated value is considered empty.

                public function __invoke(mixed $value, bool $isPropertyMissing = false): bool
{
    return $value === null;
}