Skip to main content
The package will automatically infer validation rules from the data object. For example, for the following data class:
The package will generate the following validation rules:
All these rules are inferred by RuleInferrers, special classes that will look at the types of properties and will add rules based upon that.

Configuring rule inferrers

Rule inferrers are configured in the data.php config file:
By default, five rule inferrers are enabled:

Built-in rule inferrers

SometimesRuleInferrer

Will add a sometimes rule when the property is optional.

NullableRuleInferrer

Will add a nullable rule when the property is nullable.

RequiredRuleInferrer

Will add a required rule when the property is not nullable.

BuiltInTypesRuleInferrer

Will add rules which are based upon the built-in PHP types:
  • An int or float type will add the numeric rule
  • A bool type will add the boolean rule
  • A string type will add the string rule
  • An array type will add the array rule

AttributesRuleInferrer

Will make sure that rule attributes we described above will also add their rules.

Creating custom rule inferrers

It is possible to write your own rule inferrers. You can find more information here.