ObjectValidator
ObjectValidator
Section titled “ObjectValidator”Use ObjectValidator when one DTO contains another DTO or domain object.
Create a rule
Section titled “Create a rule”Rule::object(string $field, string $targetClass): ObjectValidatorMethods
Section titled “Methods”| Method | Description |
|---|---|
required(bool $required = true) | Require the nested object. |
optional() | Allow the nested object to be missing. |
isRequired(bool $required = true) | Set requiredness explicitly. |
requiredState() | Read the current requiredness. |
Example
Section titled “Example”use Fynix\RuleSet;
ValidationRegistry::register(User::class, static fn (RuleSet $rules): array => [ $rules->object('address', Address::class),]);The nested class must have rules registered with ValidationRegistry. Fynix verifies the object type and then delegates validation to that class’s rules.