Repository navigation
Conversation
The test suite is copied from the LIVR repository again. As before, the
copy keeps negative/22-not_empty_list and negative/27-any_object adjusted,
as PHP decodes {} and [] to the same array. These are the fixes of LIVR 2.0
behavior from section 1 of the LIVR 2.5 specification.
- Aliases and "or" are transparent: their rules see the siblings of the
field, so equal_to_field compares with a sibling there. In an item of
list_of a reference to another field is a missing value (it compared the
item with itself). The data a field rule gets is not trimmed again.
- eq and one_of compare booleans as strings: {"eq": true} accepts true and
"true", {"eq": "false"} accepts false. What LIVR 2.0 accepted still
passes: {"eq": true} accepts "1" and 1, {"one_of": ["1"]} accepts true.
- Meta rules and like ignore extra arguments instead of losing the custom
rules of the validator.
- The test runners read only the directories of the test suite.
A copy of test_suite_2.5 from the LIVR repository: the cases of the rules added in LIVR 2.5, aliases, and schema_errors with the schemas that must fail to build.
LIVR 2.5 only adds rules to LIVR 2.0:
- types and numbers: boolean, not_one_of, max_decimals
- strings: digits, starts_with, ends_with, contains
- dates and times: iso_date with min and max, iso_datetime, iso_time
- presence and metarules: required_if, when, values, keys, any
- lists and modifiers: list_length, unique, split
- formats: uuid, ip, cidr, hostname, base64, hex, digest, mongo_id,
hex_color, mac, e164, semver, jwt
- checksums: luhn, credit_card, iban
The new rules are looked up after the rules of a validator, so a registered
rule with the same name replaces them. A schema with wrong arguments of
these rules throws when the validator is built, {"rule": null} included.
iso_date takes an options object with min and max now. Its LIVR 2.0 forms
are unchanged, {"iso_date": null} included; another argument, such as
{"iso_date": "today"}, throws. A number or a boolean gives WRONG_DATE.
The constructor also takes an array of options: [ 'autoTrim' => false ]
turns auto trim off even when defaultAutoTrim is on.
No new runtime dependencies. php-mock-phpunit is a dev dependency: the
tests fix the clock for "today" with it.
The rules added in LIVR 2.5, the changes of the LIVR 2.0 rules, the options array of the constructor and how tests fix the current date.
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! First of all, thank you for creating and maintaining php-validator-livr, and for reviewing and merging the earlier pull requests so quickly.
What LIVR 2.5 is
LIVR 2.5 was released on 2026-11-07. It only adds rules to LIVR 2.0: every 2.0 schema keeps working, except for a few small fixes of 2.0 behavior (section 1 of the spec) that only change schemas that never worked as written.
The reference implementation is JS
livr2.13. Perl, Dart, Rust and Raku were released with LIVR 2.5 too.What this PR does
New rules (in
lib/Validator/LIVR/Rules/, new files only):boolean,not_one_of,max_decimalsdigits,starts_with,ends_with,containsiso_datewithminandmax,iso_datetime,iso_timerequired_if,when,values,keys,anylist_length,unique,splituuid,ip,cidr,hostname,base64,hex,digest,mongo_id,hex_color,mac,e164,semver,jwtluhn,credit_card,ibanA rule the user registers under one of these names still replaces the built-in one. A schema with wrong arguments of the new rules throws when the validator is built.
Fixes of LIVR 2.0 behavior (with the 2.0 forms kept working):
orare transparent: their rules see the siblings of the field, soequal_to_fieldworks there. In an item oflist_of, a reference to another field is a missing value (before, it compared the item with itself).eqandone_ofcompare booleans as strings:{"eq": true}acceptstrueand"true". Everything 2.0 accepted still passes:{"eq": true}accepts"1"and1,{"one_of": ["1"]}acceptstrue.iso_date: an argument that is not an options object ({"iso_date": "today"}) is a schema error; before, it was silently ignored."iso_date",{"iso_date": []}and{"iso_date": null}are unchanged. A number or a boolean givesWRONG_DATEinstead ofFORMAT_ERROR.likeignore extra arguments instead of losing the validator's custom rules.Test suites: the 2.0 suite copy is updated, keeping the PHP adjustments of
negative/22-not_empty_listandnegative/27-any_objectas before.test_suite_2.5is added with its own runner (tests/06-livr_test_suite_2_5.php).Docs: a "LIVR 2.5" section in the README.
Things worth knowing
php-mock/php-mock-phpunitis added as a dev dependency only: the tests use it to fix the clock fortoday/yesterday/tomorrow. The README shows how users can do the same.new Validator\LIVR($rules, ['autoTrim' => false]), which turns auto trim off even whendefaultAutoTrimis on. The boolean second argument works as before.positive/35-object_or_listandnegative/35-object_or_listof the 2.5 suite. PHP decodes{}and[]to the same array, so they can't be told apart.Tests
On PHP 7.2 and 8.5, after a clean
composer update(the CI steps, includingphpcs):About how this was made
To be transparent: this work was done with an LLM assistant (Claude). It was checked carefully against the spec and both test suites on the lowest and the highest PHP versions in CI. I would still be very grateful for your review.
What I'd ask
A review and, if it looks good, a merge and a release whenever it's convenient for you. I'm happy to change anything: naming, structure, docs, or to split the PR differently.
Thank you!