Integrate Respect/Config and Respect/Parameter#1801
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1801 +/- ##
============================================
- Coverage 99.27% 97.12% -2.15%
- Complexity 1048 1067 +19
============================================
Files 197 198 +1
Lines 2466 2501 +35
============================================
- Hits 2448 2429 -19
- Misses 18 72 +54 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@TheRespectPanda benchmark |
|
Triggered phpbench benchmarks for PR #1801 — workflow run: https://github.com/Respect/Validation/actions/workflows/ci-perf.yml |
There was a problem hiding this comment.
Pull request overview
This PR replaces the PHP-DI-based container integration with a Respect\Config/Respect\Parameter-driven setup, introducing autowiring for rule instantiation (including for attribute-declared validators) and updating several validators to accept injectable external dependencies.
Changes:
- Replace PHP-DI container usage with
Respect\Config\ContainerinContainerRegistry, and wireRespect\Parameter\ParameterResolverinto rule construction. - Introduce
AutowiringLookupand corresponding unit tests; remove the oldNamespacedValidatorFactoryand its tests. - Update validators (e.g.,
Phone,Uuid, ISO-code rules,Attributes,Email) to support constructor DI and adjust docs/mixin generation exclusions.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/Validators/UuidTest.php | Removes PHP-DI/container-based “missing dependency” test for Uuid. |
| tests/unit/Validators/SubdivisionCodeTest.php | Removes PHP-DI/container-based “missing dependency” test for SubdivisionCode. |
| tests/unit/Validators/PhoneTest.php | Removes PHP-DI/container-based “missing dependency” tests for Phone. |
| tests/unit/Validators/LanguageCodeTest.php | Removes PHP-DI/container-based “missing dependency” test for LanguageCode. |
| tests/unit/Validators/CurrencyCodeTest.php | Removes PHP-DI/container-based “missing dependency” test for CurrencyCode. |
| tests/unit/Validators/CountryCodeTest.php | Removes PHP-DI/container-based “missing dependency” test for CountryCode. |
| tests/unit/NamespacedRuleFactoryTest.php | Deletes tests for removed NamespacedValidatorFactory. |
| tests/unit/AutowiringLookupTest.php | Adds coverage for new autowiring lookup behavior (namespaces, wrappers, DI). |
| tests/src/Validators/WithDependency.php | Adds a test-only validator to validate autowiring of constructor dependencies. |
| src/Validators/Uuid.php | Switches UUID parsing to injected/constructed UuidFactory with class_exists guard. |
| src/Validators/SubdivisionCode.php | Removes ContainerRegistry usage; supports injectable ISO-code dependencies. |
| src/Validators/Phone.php | Removes ContainerRegistry usage; supports injectable PhoneNumberUtil and ISO-code dependency. |
| src/Validators/LanguageCode.php | Removes ContainerRegistry usage; supports injectable Languages dependency. |
| src/Validators/Email.php | Removes func_num_args() guard so autowiring doesn’t silently force fallback behavior. |
| src/Validators/CurrencyCode.php | Removes ContainerRegistry usage; supports injectable Currencies dependency. |
| src/Validators/CountryCode.php | Removes ContainerRegistry usage; supports injectable Countries dependency. |
| src/Validators/Attributes.php | Adds optional ParameterResolver to autowire attribute validators via constructor resolution. |
| src/NamespacedValidatorFactory.php | Removes the legacy namespaced factory implementation. |
| src/ContainerRegistry.php | Replaces PHP-DI definitions with Respect\Config definitions and sets up AutowiringLookup. |
| src/AutowiringLookup.php | Adds fluent factory that autowires constructor dependencies via Respect\Parameter. |
| src-dev/Commands/LintMixinCommand.php | Excludes newly autowired dependency types from generated mixin interfaces. |
| docs/validators/Uuid.md | Documents injectable UuidFactory parameter. |
| docs/validators/Phone.md | Documents new constructor shape (needs correction for parameter order/types). |
| docs/validators/Attributes.md | Documents injectable resolver parameter. |
| docs/configuration.md | Updates container documentation from PHP-DI to Respect\Config. |
| composer.lock | Updates lockfile to reflect dependency changes. |
| composer.json | Removes PHP-DI, adds respect/config and respect/parameter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fb22074 to
6d9886b
Compare
|
Benchmarks show regression similar to previous FluentGen PR, which is strange. https://github.com/Respect/Validation/actions/runs/28167881836
A possible fix is to mark validators that take injectable parameters explicitly, and moving the |
6d9886b to
199df18
Compare
henriquemoody
left a comment
There was a problem hiding this comment.
There's some documentation to update, look for ContainerRegistry in the docs/. It looks good, though!
|
Do like the idea of being deliberate to which validators we want to resolve arguments. I saw most of the performance hits are no validators like AllOf, AnyOf that have constructor arguments. I'm also fine doing it on another PR. |
Yes, that's what I mentioned here! I think there could be a regain in performance. The question is how to mark that explicitly in a way that the ecosystem supports (eg custom validators). Attributes are a probable answer, but that's complicated (where should it stay?).
I currently dislike all of those options 😞 I don't actually know if that's where most of the perf loss went. The ideal path is to measure first what are the hot paths. I need a day or two for that and for a nice refined solution. |
Seems like something for the resolver, to be honest. Probably means we'd have two different resolvers as well, one that automatically handlers that, and one that expects a PHP attribute. -- |
fb10d33 to
71c599c
Compare
|
@henriquemoody addressed the items. Respect/Parameter#33 is still under review and I would like to have it and release another |
Replace the PHP-DI container with Respect/Config: ContainerRegistry now builds a Respect\Config\Container, registering the rules' external dependencies (PHP ISO Codes, libphonenumber, ramsey/uuid) and a ParameterResolver. Instantiate rules through a new AutowiringLookup: a Respect\Fluent FluentFactory that resolves the rule name and autowires its constructor dependencies from the container via Respect\Parameter, wrapped by FluentValidatorFactory. The dead NamespacedValidatorFactory is removed. Drop static ContainerRegistry access from CountryCode, CurrencyCode, LanguageCode, SubdivisionCode, Phone and Uuid: each accepts its external dependency and otherwise constructs it directly, guarded by class_exists for the missing-package error. Inject a ParameterResolver into Attributes so attribute-declared rules are autowired too. Fix Email: drop the func_num_args() guard, which autowiring defeats (the resolver always passes the defaulted argument), so v::email() uses egulias again instead of silently falling back to filter_var. Exclude the autowired dependency types from the generated mixins, update the docs, and add AutowiringLookupTest.
71c599c to
7d39cc2
Compare
Replace the PHP-DI container with Respect/Config: ContainerRegistry now builds a Respect\Config\Container, registering the rules' external dependencies (PHP ISO Codes, libphonenumber, ramsey/uuid) and a ParameterResolver.
Instantiate rules through a new AutowiringLookup: a Respect\Fluent FluentFactory that resolves the rule name and autowires its constructor dependencies from the container via Respect\Parameter, wrapped by FluentValidatorFactory. The dead NamespacedValidatorFactory is removed.
Drop static ContainerRegistry access from CountryCode, CurrencyCode, LanguageCode, SubdivisionCode, Phone and Uuid: each accepts its external dependency and otherwise constructs it directly, guarded by class_exists for the missing-package error. Inject a ParameterResolver into Attributes so attribute-declared rules are autowired too.
Fix Email: drop the func_num_args() guard, which autowiring defeats (the resolver always passes the defaulted argument), so v::email() uses egulias again instead of silently falling back to filter_var.
Exclude the autowired dependency types from the generated mixins, update the docs, and add AutowiringLookupTest.