Skip to content

ObjectValidator

Use ObjectValidator when one DTO contains another DTO or domain object.

Rule::object(string $field, string $targetClass): ObjectValidator
MethodDescription
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.
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.