validator icon indicating copy to clipboard operation
validator copied to clipboard

Extract rule name and options to separate collector

Open vjik opened this issue 1 year ago • 4 comments

My suggestion:

  1. Remove method RuleInterface::getName().
  2. Remove interface RuleWithOptionsInterface.
  3. Remove RulesDumper.
  4. Create new RulesConvertor that would can be configured for usage with custom rules also.

Benefits:

  • more clear rule classes
  • allows move all default values to rule handlers, that allow override default values globally.

vjik avatar Apr 02 '24 11:04 vjik

  1. As an author of the custom rule, what would be different for me to implement / use the rule?
  2. What if I want to ship it in a Composer package?
  3. As a rule user, what would be different for me?

samdark avatar Apr 02 '24 21:04 samdark

  1. As an author of the custom rule, what would be different for me to implement / use the rule?

Implementation:

  • method RuleInterface::getName() need to implement only when user used convertation rules to array
  • if options needed, then yet another class for convert rule to array will be required (also user can implement new interface in rule).

Usage:

  • add ability to change converatation to array for any rule.
  1. What if I want to ship it in a Composer package?

It can be configured via Yii Config or manually.

  1. As a rule user, what would be different for me?

See 1.

vjik avatar Apr 03 '24 08:04 vjik

I like the ability to configure it, but I don't think we need to separate this information, since it logically belongs to rule itself.

samdark avatar Apr 03 '24 09:04 samdark

In some cases need ability to configure converter rule to array. For example date format in date rule. In this case need to use separate converter.

vjik avatar Apr 03 '24 10:04 vjik