Skip to content

Add Ref for named container references in Autowire#73

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:autoref
Mar 21, 2026
Merged

Add Ref for named container references in Autowire#73
alganet merged 1 commit intoRespect:masterfrom
alganet:autoref

Conversation

@alganet
Copy link
Member

@alganet alganet commented Mar 21, 2026

Ref is a value object that maps a constructor parameter to a container key, enabling Autowire for cases where type-based resolution is insufficient (same interface with multiple implementations, or builtin types like array/string).

@codecov-commenter
Copy link

codecov-commenter commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b56c276) to head (48f13a6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master       #73   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       152       155    +3     
===========================================
  Files              5         6    +1     
  Lines            313       319    +6     
===========================================
+ Hits             313       319    +6     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a Ref value object to enable key-based container lookups for specific constructor parameters during Autowire, covering cases where type-based resolution is ambiguous or not possible (e.g., builtins/arrays or multiple implementations).

Changes:

  • Introduce Respect\Config\Ref as a small value object holding a container key (id).
  • Update Autowire::cleanupParams() to resolve explicitly provided Ref params via $container->get($ref->id).
  • Add PHPUnit coverage for Ref itself and for Autowire behavior using Ref (class, builtin, array, and precedence with type-based autowiring).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Ref.php Adds the Ref value object used to represent container-key references.
src/Autowire.php Resolves explicitly set constructor params when the value is a Ref.
tests/RefTest.php Verifies Ref stores the id and that it is readonly.
tests/AutowireTest.php Adds coverage for Ref-based param binding and precedence rules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ref is a value object that maps a constructor parameter to a container
key, enabling Autowire for cases where type-based resolution is
insufficient (same interface with multiple implementations, or builtin
types like array/string).
@alganet alganet marked this pull request as ready for review March 21, 2026 00:59
@alganet alganet merged commit e744aa2 into Respect:master Mar 21, 2026
3 checks passed
@alganet alganet deleted the autoref branch March 21, 2026 00:59
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.

3 participants