Skip to content

Introduce Instantiator types (Autowire and Factory)#71

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:autowire
Mar 20, 2026
Merged

Introduce Instantiator types (Autowire and Factory)#71
alganet merged 1 commit intoRespect:masterfrom
alganet:autowire

Conversation

@alganet
Copy link
Member

@alganet alganet commented Mar 20, 2026

Extract Factory (always-new instances) and Autowire (type-hint-based DI resolution) from Instantiator, replacing the mode string with polymorphism. Refactor Instantiator to lazily initialize reflection and constructor params, accept initial params in the constructor, and remove the embedded class-name parsing that now lives in Container's createInstantiator().

Container gains createInstantiator() with new/autowire modifier support, Autowire integration via offsetSet(), class_exists() check in has(), ReflectionException wrapping in getItem(), Closure-aware lazyLoad(), and set()/loadArray() handling for Instantiator/Closure values.

Add AutowireTest, FactoryTest, NotFoundExceptionTest, and extend ContainerTest and InstantiatorTest to cover magic methods, deferred config, loadString/loadFile error paths, and edge cases (102 tests).

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.68%. Comparing base (2a8e237) to head (cc5e21b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master      #71       +/-   ##
=============================================
+ Coverage     86.78%   99.68%   +12.89%     
- Complexity      132      153       +21     
=============================================
  Files             2        4        +2     
  Lines           280      317       +37     
=============================================
+ Hits            243      316       +73     
+ Misses           37        1       -36     

☔ 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

This PR refactors instantiation behavior in the DI/config container by replacing the previous mode-string approach with polymorphic instantiators (Factory and Autowire), and extends Container to support these new instantiation modifiers and behaviors.

Changes:

  • Introduces Factory (always-new instances) and Autowire (constructor type-hint resolution via container) as Instantiator subclasses.
  • Refactors Instantiator for lazy reflection/constructor-param initialization and constructor-provided initial params.
  • Updates Container to support instantiator modifiers (new, autowire), closure-aware lazy loading, improved has() behavior, and expanded test coverage.

Reviewed changes

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

Show a summary per file
File Description
src/Instantiator.php Lazifies reflection/constructor handling; removes mode parsing; supports initial params.
src/Factory.php Adds always-new instantiator behavior via subclassing.
src/Autowire.php Adds container-aware constructor autowiring logic.
src/Container.php Adds instantiator creation with modifiers, autowire integration, closure-aware lazy loading, and updated has()/getItem() behavior.
composer.json Bumps branch alias to 3.0-dev.
tests/AutowireTest.php Adds coverage for autowiring behavior and container integration.
tests/FactoryTest.php Adds coverage ensuring factories always create new instances.
tests/NotFoundExceptionTest.php Adds PSR-11 interface/Throwable coverage for NotFoundException.
tests/InstantiatorTest.php Adds coverage for new Instantiator behaviors (initial params, getters, edge cases).
tests/ContainerTest.php Extends coverage for magic methods, deferred config, modifier parsing, closures, and error paths.

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

Extract Factory (always-new instances) and Autowire (type-hint-based
DI resolution) from Instantiator, replacing the mode string with
polymorphism. Refactor Instantiator to lazily initialize reflection
and constructor params, accept initial params in the constructor, and
remove the embedded class-name parsing that now lives in Container's
createInstantiator().

Container gains createInstantiator() with `new`/`autowire` modifier
support, Autowire integration via offsetSet(), class_exists() check
in has(), ReflectionException wrapping in getItem(), Closure-aware
lazyLoad(), and set()/loadArray() handling for Instantiator/Closure
values.

Add AutowireTest, FactoryTest, NotFoundExceptionTest, and extend
ContainerTest and InstantiatorTest to cover magic methods, deferred
config, loadString/loadFile error paths, and edge cases (102 tests).
@alganet alganet marked this pull request as ready for review March 20, 2026 21:45
@alganet alganet merged commit 652685c into Respect:master Mar 20, 2026
3 checks passed
@alganet alganet deleted the autowire branch March 20, 2026 21:50
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