mini\Validator\Validator::custom()
Method
public
Signature
public function custom(Closure $callback): static
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$callback |
Closure |
required | Documentation missing |
Returns
static
Documentation
Custom validation callback (for server-side validation only)
Use this for PHP-specific validations that cannot be exported to JSON Schema, such as instance checks, filter_var validations, or any custom PHP logic.
The callback should return truthy if valid, falsy if invalid.
When validating object properties or array items, the callback can optionally accept a second parameter for the parent context (containing object/array):
Examples:
// Simple validation (just the value)
$validator->custom(fn($v) => $v instanceof SomeClass)
// With parent context (for relational validation)
$userValidator = (new Validator)
->type('object')
->forProperty('password_confirmation',
(new Validator)->custom(fn($confirmation, $user) =>
$confirmation === $user['password']
)
);