0 follower

Interface Yiisoft\Validator\DumpedRuleInterface

ExtendsYiisoft\Validator\RuleInterface
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\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 extended version of {@see RuleInterface} which allows exporting a rule options and name customization. It's useful for passing to frontend for further identification and implementing client-side validation. If you don't need that (for example for REST API), use {@see RuleInterface} instead.

Public Methods

Hide inherited methods

Method Description Defined By
getHandler() A matching handler name or an instance used for processing this rule. Yiisoft\Validator\RuleInterface
getName() Returns the name of a rule used during conversion to array. It's used for identification on the frontend with further implementing of client-side validation. Yiisoft\Validator\DumpedRuleInterface
getOptions() Gets a rule options as associative array. It's used for identification on the frontend with further implementing of client-side validation. Usually it's just a mapping between rule property names and values. Yiisoft\Validator\DumpedRuleInterface

Method Details

Hide inherited methods

getHandler() public abstract method

Defined in: Yiisoft\Validator\RuleInterface::getHandler()

A matching handler name or an instance used for processing this rule.

While not required, for naming of handlers' classes it's recommended to use a rule class name with "Handler" suffix, so for FilledAtLeast rule class name the handler class name will be FilledAtLeastHandler and so on.

All packages handlers are stored within the same namespace as rules, but this is not a strict requirement.

public abstract Yiisoft\Validator\RuleHandlerInterface|string getHandler ( )
return Yiisoft\Validator\RuleHandlerInterface|string

A rule handler name (for example my-handler) or an instance (for example new MyRuleHandler()).

                public function getHandler(): string|RuleHandlerInterface;

            
getName() public abstract method

Returns the name of a rule used during conversion to array. It's used for identification on the frontend with further implementing of client-side validation.

public abstract string getName ( )
return string

A rule name.

                public function getName(): string;

            
getOptions() public abstract method

Gets a rule options as associative array. It's used for identification on the frontend with further implementing of client-side validation. Usually it's just a mapping between rule property names and values.

For a example, for this rule:

new SomeRule(property1: 'value1', property2: 'value2');

the options will be:

[
    'property1' => $this->>property1,
    'property2' => $this->>property2,
    // ...
];

For messages the value is a nested array with the following structure (below is a result of the method call):

'message' => [ // Array is used with no parameters either.
    'template => 'A message without parameters.',
    'parameters' => [], // Explicitly specified even for empty parameters.
],
'anotherMessage' => [
    'template' => 'A message with {parameter}.', // Handler dependent parameters
    'parameters' => ['property4' => $this->property4], // Property dependent parameters
],
'doNotUseThisMessage' => 'Do not use this message.' // This is wrong. Use example above for consistent structure.

Note that the values that can't be serialized to frontend such as callable must be excluded because they will be useless on frontend. No exceptions are thrown in such cases.

public abstract array getOptions ( )
return array

A rule options.

                public function getOptions(): array;