Interface Yiisoft\Validator\DumpedRuleInterface
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
| 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
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 |
|---|---|---|
public function getHandler(): string|RuleHandlerInterface;
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;
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;
Signup or Login in order to comment.