Skip to main content
Rule inferrers automatically generate validation rules for properties within a data object.

RuleInferrer Interface

Implement the RuleInferrer interface:

Parameters

  • property - DataProperty object representing the property (read more)
  • rules - PropertyRules collection of previously inferred rules
  • context - ValidationContext containing:
    • payload - Current payload for the data object being validated
    • fullPayload - Full payload being validated
    • validationPath - Path from full payload to current payload

Working with PropertyRules

Adding Rules

Automatic Rule Replacement

When adding a rule of the same type, the previous version is removed:

Adding String Rules

Checking for Rule Types

Removing Rules

Example Implementation

Registration

Rule inferrers must be registered in the config/data.php config file:

Return Value

A rule inferrer must always return a PropertyRules collection.