Skip to content

feat(validation): introduce custom Bind rule system#237

Merged
techmahedy merged 2 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Apr 4, 2026
Merged

feat(validation): introduce custom Bind rule system#237
techmahedy merged 2 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Copy Markdown
Member

Overview

This PR adds a first-class custom rule binding API (Bind::to()) to Doppar, enabling framework users and package authors to register custom validation rules directly in the pipeline without modifying core files.
Key Features

  • Custom rule registration: Any class implementing RuleInterface can be registered directly in the validation pipeline.
  • Conditional execution: Rules can be configured to run only under specific input conditions, ensuring flexible and context-aware validation.

Example Usage

$sanitized = $request->sanitize([
    'status' => 'required|in:active,inactive,pending',
    
    // Always runs
    'domain' => Bind::to(new Domain()),      

    // Runs only when status is 'active'
    'phone'  => Bind::to(new PhoneNumber())->context(['status' => 'active'])
]);
  • If status is "active", both Domain and PhoneNumber rules run.
  • If status is "inactive" or "pending", PhoneNumber is skipped silently, while Domain still runs.

How context() Works

Scenario Behaviour
Bind::to(new Domain()) Always runs
->context(['status' => 'active']) Runs only when $input['status'] === 'active'
->context(['a' => '1', 'b' => '2']) Runs only when all conditions match
Condition not met Rule is silently skipped (treated as passing)

@techmahedy techmahedy added the feat new feature label Apr 4, 2026
@techmahedy techmahedy merged commit 919b13c into doppar:3.x Apr 4, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant