Support loading Container self-reference from Container#290
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for loading a Container self-reference from the Container itself. This enables the container to inject itself into factory functions and allows Container::class to be used as a class name reference in routing and dependency injection contexts.
Key changes:
- Container can now return itself when
Container::classis requested viagetObject() - Factory functions can now receive the Container as a dependency parameter
Container::classcan be used in routing configurations and will be resolved to the actual container instance
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Container.php |
Implements self-reference support in loadObject() and getObject() methods, adds assertion to prevent Container in callable() |
src/App.php |
Updates middleware loading to support Container::class as a loadable class |
src/Io/RouteHandler.php |
Adds logic to resolve Container::class to container instance in route handlers |
tests/ContainerTest.php |
Adds comprehensive test coverage for Container self-reference scenarios including default behavior, explicit configuration, PSR-11 adapter, and recursive detection |
tests/AppTest.php |
Updates test expectations to account for Container::class resolution |
tests/Io/RouteHandlerTest.php |
Adds tests for Container::class usage in routing contexts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This changeset adds support for loading a
Containerself-reference from theContainer. On its own, this is rarely useful as theContainerhas no public API exposed at the moment. This is mostly done as an internal preparation at the moment, but may be exposed as part of our public API that allows us to reuse this logic for more classes in a follow-up.Builds on top of #289, #284 and others