Introduce Instantiator types (Autowire and Factory)#71
Merged
alganet merged 1 commit intoRespect:masterfrom Mar 20, 2026
Merged
Introduce Instantiator types (Autowire and Factory)#71alganet merged 1 commit intoRespect:masterfrom
alganet merged 1 commit intoRespect:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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) andAutowire(constructor type-hint resolution via container) asInstantiatorsubclasses. - Refactors
Instantiatorfor lazy reflection/constructor-param initialization and constructor-provided initial params. - Updates
Containerto support instantiator modifiers (new,autowire), closure-aware lazy loading, improvedhas()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).
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.
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/autowiremodifier 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).