Skip to content

Reference overview

Fynix v3 separates rule construction from validation. Use Rule for standalone fields, Rule::on() or RuleSet for DTO-owned fields, and ValidationHandler when validating a complete object graph.

  1. Create rules through Rule, Rule::on(), or a RuleSet factory.
  2. Configure rules with immutable fluent methods.
  3. Register DTO rules with ValidationRegistry when validating objects.
  4. Call ValidationHandler::validate() at the application boundary.
  5. Return strings for simple forms or ValidationError objects for API responses.
use Fynix\Rule;
$standalone = Rule::string('firstName')->min(2)->max(50);
$scoped = Rule::on(User::class)->email('email')->max(255);

Rule::on() checks that the owner class and property exist. Direct validator constructors and the removed Rules::for() builder are not part of v3’s public API.

use Fynix\RuleSet;
use Fynix\ValidationRegistry;
ValidationRegistry::register(
User::class,
static fn (RuleSet $rules): array => [
$rules->string('firstName')->min(2)->max(50),
$rules->email('email')->max(255),
]
);

The registry factory receives a RuleSet, not a DTO instance. It returns Validatable rules for the registered class.

ClassResponsibility
RuleConstruct standalone and scoped validators.
ScopedRuleValidate owner classes and declared properties while constructing rules.
RuleSetCreate scoped rules inside registry factories.
ValidationRegistryStore and retrieve class rule definitions.
ValidationHandlerValidate objects, nested DTOs, arrays, and batches.
ValidationErrorCarry field, message, code, and parameters.
AllOf, AnyOf, NotCompose reusable validation rules.

Fynix includes primitive validators (string, boolean, integer, decimal, number), format validators (email, url, uuid, ipAddress, regex, phoneNumber, dateTime), collection validators (array, objectArray), upload validators (file, image, images), and domain validators (password, username, enum, object).

Continue with Rule, RuleSet, and registry or browse the validator overview.