Skip to content

feat: enhanced wildcard validation - #15

Open
debba wants to merge 3 commits into
leafsphp:v3.xfrom
debba:feat-enhanced-wildcard-validation
Open

debba wants to merge 3 commits into
leafsphp:v3.xfrom
debba:feat-enhanced-wildcard-validation

Conversation

@debba

@debba debba commented Aug 22, 2025

Copy link
Copy Markdown

What kind of change does this PR introduce? (pls check at least one)

  • Bugfix
  • [ x] Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe below

Description

Enhanced the Form validation system with a wildcard support for complex nested array structures. This enables validation of dynamic data like orders with variable products, user lists with different attributes, and other nested collections.

Real-world Use Cases

// E-commerce orders with variable products
$rules = [
    "orders.*.id" => "numeric",
    "orders.*.products.*.name" => "string",
    "orders.*.products.*.available" => "optional|boolean"
];

// User management with dynamic attributes
$rules = [
    "users.*.profile.*.key" => "string",
    "users.*.permissions.*" => "string"
];

// Categories with nested items and tags
$rules = [
    "categories.*.items.*.tags.*" => "string",
    "categories.*.metadata.*.value" => "optional|string"
];

Summary

  • Enhanced wildcard validation system to support complex nested array structures
  • Added handling for multiple wildcard levels and deeply nested data
  • Improved error reporting with accurate field path tracking
  • Added tests

debba added 2 commits August 22, 2025 12:42
  - Fix optional field validation to properly handle null, empty string, and empty array
  - Add explicit boolean value conversion to string for validation
  - Improve missing value detection with strict type checking
  - Implement validateWildcardPath() method for complex nested validation
  - Add support for multiple wildcard levels (field.*.subfield.*)
  - Enhance getValue/setValue methods with improved dot notation support
  - Add recursive wildcard handling for deeply nested structures
  - Improve error reporting with accurate field paths for wildcards
  - Maintain backward compatibility with existing validation patterns
  - Added tests
@debba debba changed the title Feat enhanced wildcard validation feat: enhanced wildcard validation Aug 22, 2025
@mychidarko

Copy link
Copy Markdown
Member

Thanks for this. No CI has run on the PR, and the suite doesn't start locally on PHP 8.4 because of the old Pest version in the lockfile, so I can't confirm the new tests pass. The change also touches how wildcard and nested fields validate and adds a return type to addError, which can affect existing apps. Holding this for Michael to review.

@mychidarko

Copy link
Copy Markdown
Member

Thanks for this, @debba. The wildcard work looks good. One request before we can merge: could you split the falsy-value change out into a separate PR? Currently 0, "0" and false are no longer treated as missing for required/optional, which changes behaviour for existing non-nested validation. We'd like to ship that on its own, as a minor version with a changelog note. Could you also keep the : void return type on addError out of this PR? It would break subclasses that override addError without it. The wildcard validation and the new helpers can go in here. Thanks!

@debba

debba commented Nov 17, 2026

Copy link
Copy Markdown
Author

Thanks for taking a look! I’ll keep the wildcard changes and helpers in this PR, restore the current required and optional behavior, and drop the : void from addError().

Then I’ll open a separate PR from v3.x for the falsy-value change, with tests for 0, "0", and false and a changelog note for the minor release.

Does that sound like the split you had in mind?

@mychidarko

Copy link
Copy Markdown
Member

Yes that's perfect 👌🏽

@mychidarko

Copy link
Copy Markdown
Member

Thanks @debba, CI is green now and addError keeps its old signature. The falsy-value change is still in this PR though: the optional check and the missing-value check in Form.php now treat 0, "0" and false as present. Could you restore the previous behaviour here and move that change to its own PR as agreed? The @Version bump to 3.1.0 can wait for release as well.

@debba

debba commented Nov 18, 2026

Copy link
Copy Markdown
Author

Thanks for checking! I’ll take out the version bump and leave it for the release.

I had another look at the falsy checks. They already landed in v3.x through #14. I can see them in the PR diff too, but they don’t show up when I compare this branch with the current tip of v3.x. That’s why I put the tests and changelog note in #17.

Did you want me to revert the behavior from #14 as well, or is it okay to keep what’s already in v3.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants