Final Class Yiisoft\Validator\Helper\PropagateOptionsHelper
| Inheritance | Yiisoft\Validator\Helper\PropagateOptionsHelper |
|---|
A helper class used to propagate options' values from a single parent rule to its child rules at all nesting levels recursively.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| propagate() | Propagates options' values from a single parent rule to its all child rules at all nesting levels recursively. | Yiisoft\Validator\Helper\PropagateOptionsHelper |
| propagateToRule() | Performs propagation of options' values for a single pair of one parent rule and one of its direct child rules. | Yiisoft\Validator\Helper\PropagateOptionsHelper |
Method Details
Propagates options' values from a single parent rule to its all child rules at all nesting levels recursively.
The following options' values are propagated:
$skipOnEmpty(both rules must implement {@see \Yiisoft\Validator\SkipOnEmptyInterface}).$skipOnError(both rules must implement {@see \Yiisoft\Validator\SkipOnErrorInterface}).$when(both rules must implement {@see \Yiisoft\Validator\WhenInterface}).
| public static array propagate ( Yiisoft\Validator\RuleInterface $parentRule, iterable $childRules ) | ||
| $parentRule | Yiisoft\Validator\RuleInterface |
A parent rule which options' values need to be propagated. |
| $childRules | iterable |
Direct child rules for this particular parent rule which options' values must be changed to be the same as in parent rule. |
| return | array |
A list of child rules of the same nesting level with changed options' values or unchanged if none of the required interfaces were implemented. The order is preserved. |
|---|---|---|
public static function propagate(RuleInterface $parentRule, iterable $childRules): array
{
$rules = [];
foreach ($childRules as $childRule) {
$rules[] = self::propagateToRule($parentRule, $childRule);
}
return $rules;
}
Performs propagation of options' values for a single pair of one parent rule and one of its direct child rules.
If the child rule also supports such propagation, it delegates the further propagation to {@see \Yiisoft\Validator\PropagateOptionsInterface::propagateOptions()} implementation in this child rule.
| public static Yiisoft\Validator\RuleInterface propagateToRule ( Yiisoft\Validator\RuleInterface $parentRule, Yiisoft\Validator\RuleInterface $childRule ) | ||
| $parentRule | Yiisoft\Validator\RuleInterface |
A parent rule which options' values need to be propagated. |
| $childRule | Yiisoft\Validator\RuleInterface |
One of the direct child rules for this particular parent rule which options' values must be changed to be the same as in parent rule. |
| return | Yiisoft\Validator\RuleInterface |
The same child rule instance with changed options' values or unchanged if none of the required interfaces were implemented. |
|---|---|---|
public static function propagateToRule(RuleInterface $parentRule, RuleInterface $childRule): RuleInterface
{
if ($parentRule instanceof SkipOnEmptyInterface && $childRule instanceof SkipOnEmptyInterface) {
$childRule = $childRule->skipOnEmpty($parentRule->getSkipOnEmpty());
}
if ($parentRule instanceof SkipOnErrorInterface && $childRule instanceof SkipOnErrorInterface) {
$childRule = $childRule->skipOnError($parentRule->shouldSkipOnError());
}
if ($parentRule instanceof WhenInterface && $childRule instanceof WhenInterface) {
$childRule = $childRule->when($parentRule->getWhen());
}
if ($childRule instanceof PropagateOptionsInterface) {
$childRule->propagateOptions();
}
return $childRule;
}
Signup or Login in order to comment.