0 follower

Final Class Yiisoft\Validator\Helper\SkipOnEmptyNormalizer

InheritanceYiisoft\Validator\Helper\SkipOnEmptyNormalizer

A helper class used to normalize different types of "skip on empty" values including shortcuts to a callable ({@see SkipOnEmptyInterface}).

Public Methods

Hide inherited methods

Method Description Defined By
normalize() Normalizes different types of "skip on empty" values including shortcuts to a callable: Yiisoft\Validator\Helper\SkipOnEmptyNormalizer

Method Details

Hide inherited methods

normalize() public static method

Normalizes different types of "skip on empty" values including shortcuts to a callable:

  • null and false values are normalized to {@see \Yiisoft\Validator\EmptyCondition\NeverEmpty}.
  • true value is normalized to {@see \Yiisoft\Validator\EmptyCondition\WhenEmpty}.
  • A callable is left as is.
  • Other types are rejected causing the exception.
public static callable normalize ( boolean|callable|null $skipOnEmpty )
$skipOnEmpty boolean|callable|null

Raw "skip on empty" value of any type.

return callable

An empty condition as a callable.

                public static function normalize(bool|callable|null $skipOnEmpty): callable
{
    if ($skipOnEmpty === false || $skipOnEmpty === null) {
        return new NeverEmpty();
    }
    if ($skipOnEmpty === true) {
        return new WhenEmpty();
    }
    return $skipOnEmpty;
}