0 follower

Interface Yiisoft\Validator\WhenInterface

Implemented byYiisoft\Validator\Rule\AbstractCompare, Yiisoft\Validator\Rule\AbstractNumber, Yiisoft\Validator\Rule\AnyRule, Yiisoft\Validator\Rule\BooleanValue, Yiisoft\Validator\Rule\Callback, Yiisoft\Validator\Rule\Compare, Yiisoft\Validator\Rule\Composite, Yiisoft\Validator\Rule\Count, Yiisoft\Validator\Rule\Date\BaseDate, Yiisoft\Validator\Rule\Date\Date, Yiisoft\Validator\Rule\Date\DateTime, Yiisoft\Validator\Rule\Date\Time, Yiisoft\Validator\Rule\Each, Yiisoft\Validator\Rule\Email, Yiisoft\Validator\Rule\Equal, Yiisoft\Validator\Rule\FilledAtLeast, Yiisoft\Validator\Rule\FilledOnlyOneOf, Yiisoft\Validator\Rule\GreaterThan, Yiisoft\Validator\Rule\GreaterThanOrEqual, Yiisoft\Validator\Rule\Image\Image, Yiisoft\Validator\Rule\In, Yiisoft\Validator\Rule\InEnum, Yiisoft\Validator\Rule\Integer, Yiisoft\Validator\Rule\Ip, Yiisoft\Validator\Rule\Json, Yiisoft\Validator\Rule\Length, Yiisoft\Validator\Rule\LessThan, Yiisoft\Validator\Rule\LessThanOrEqual, Yiisoft\Validator\Rule\Nested, Yiisoft\Validator\Rule\NotEqual, Yiisoft\Validator\Rule\Number, Yiisoft\Validator\Rule\Regex, Yiisoft\Validator\Rule\Required, Yiisoft\Validator\Rule\StopOnError, Yiisoft\Validator\Rule\StringValue, Yiisoft\Validator\Rule\Subset, Yiisoft\Validator\Rule\TrueValue, Yiisoft\Validator\Rule\Type\BooleanType, Yiisoft\Validator\Rule\Type\FloatType, Yiisoft\Validator\Rule\Type\IntegerType, Yiisoft\Validator\Rule\Type\StringType, Yiisoft\Validator\Rule\UniqueIterable, Yiisoft\Validator\Rule\Url, Yiisoft\Validator\Rule\Uuid

An optional interface for rules to implement. It allows applying validation for a rule within a group of other rules under certain conditions.

The package ships with {@see \Yiisoft\Validator\WhenTrait} which already implements that interface. All you have to do is include it in the rule class along with the interface.

Psalm Types

Name Value
WhenType null|callable

Public Methods

Hide inherited methods

Method Description Defined By
getWhen() Returns current "when" value. Yiisoft\Validator\WhenInterface
when() Changes current "when" value. Must be immutable. Yiisoft\Validator\WhenInterface

Method Details

Hide inherited methods

getWhen() public abstract method

Returns current "when" value.

public abstract Closure|null getWhen ( )

                public function getWhen(): ?Closure;

            
when() public abstract method

Changes current "when" value. Must be immutable.

See also Yiisoft\Validator\ValidationContext for publicly available methods and properties for building condition.

public abstract $this when ( Closure|null $value )
$value Closure|null
return $this

The new instance of a rule with a changed value.

                public function when(?Closure $value): static;