Skip to content

Integrate Respect/Config and Respect/Parameter#1801

Merged
alganet merged 1 commit into
Respect:mainfrom
alganet:config-integration
Jun 26, 2026
Merged

Integrate Respect/Config and Respect/Parameter#1801
alganet merged 1 commit into
Respect:mainfrom
alganet:config-integration

Conversation

@alganet

@alganet alganet commented Jun 25, 2026

Copy link
Copy Markdown
Member

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.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.12%. Comparing base (42f08d7) to head (7d39cc2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alganet alganet requested a review from Copilot June 25, 2026 11:15
@alganet

alganet commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

@TheRespectPanda benchmark

@TheRespectPanda

Copy link
Copy Markdown
Contributor

Triggered phpbench benchmarks for PR #1801 — workflow run: https://github.com/Respect/Validation/actions/workflows/ci-perf.yml

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\Container in ContainerRegistry, and wire Respect\Parameter\ParameterResolver into rule construction.
  • Introduce AutowiringLookup and corresponding unit tests; remove the old NamespacedValidatorFactory and 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.

Comment thread src/Validators/Attributes.php
Comment thread src/AutowiringLookup.php Outdated
Comment thread src/AutowiringLookup.php
Comment thread src/Validators/Phone.php
Comment thread docs/validators/Phone.md Outdated
@alganet alganet force-pushed the config-integration branch 2 times, most recently from fb22074 to 6d9886b Compare June 25, 2026 11:46
@alganet

alganet commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

Benchmarks show regression similar to previous FluentGen PR, which is strange.

https://github.com/Respect/Validation/actions/runs/28167881836

I'm still investigating those regressions. They're real regressions. Indirection has slowed things down a handful of microseconds. I don't have a fix for it right now (both resolving arguments and building the chain got a little slower).

A possible fix is to mark validators that take injectable parameters explicitly, and moving the AutowiringLookup to Fluent so we skip a composite method call. I would prefer to deal with those in a separate PR!

@alganet alganet force-pushed the config-integration branch from 6d9886b to 199df18 Compare June 25, 2026 11:57
@alganet alganet marked this pull request as ready for review June 25, 2026 12:02
@alganet alganet requested a review from henriquemoody June 25, 2026 12:02
Comment thread docs/validators/Attributes.md Outdated

@henriquemoody henriquemoody left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some documentation to update, look for ContainerRegistry in the docs/. It looks good, though!

Comment thread src/Validators/Attributes.php Outdated
Comment thread src/AutowiringLookup.php Outdated
Comment thread src/ContainerRegistry.php
Comment thread src/NamespacedValidatorFactory.php
@henriquemoody

Copy link
Copy Markdown
Member

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.

@alganet

alganet commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

Do like the idea of being deliberate to which validators we want to resolve arguments.

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?).

  • Attribute lookup stays in Validation: another introspection layer (I'm trying to move those out)
  • Attribute goes into Fluent (now Fluent needs to know Parameter)
  • Attribute goes into Config (likely Parameter stops being the main interface, and the container resolves)

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.

@henriquemoody

henriquemoody commented Jun 25, 2026

Copy link
Copy Markdown
Member

Attributes are a probable answer, but that's complicated (where should it stay?).

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.

--
Edit: The reality is that dealing with arguments like we are doing here is something that can only be solved by the Resolver, it's not a standard behavior, so I think it should be there.

@alganet alganet force-pushed the config-integration branch 2 times, most recently from fb10d33 to 71c599c Compare June 25, 2026 21:56
@alganet

alganet commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

@henriquemoody addressed the items.

Respect/Parameter#33 is still under review and I would like to have it and release another respect\parameter though, but it would be nice if you could resolve/elaborate on the other PR comments meanwhile.

Comment thread src/NamespacedValidatorFactory.php
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.
@alganet alganet force-pushed the config-integration branch from 71c599c to 7d39cc2 Compare June 25, 2026 23:08
@alganet alganet merged commit 1b31207 into Respect:main Jun 26, 2026
12 checks passed
@alganet alganet deleted the config-integration branch June 26, 2026 00:02
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.

4 participants