Support any type for container variables and factory functions#307
Open
clue wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR relaxes FrameworkX\Container’s value restrictions so container variables and variable factory functions can yield any PHP value type (e.g. resource), while continuing to treat Closure values as factories (and rejecting factories that return a Closure).
Changes:
- Loosens
Container’s internal type constraints by removing the “object|scalar|array|null” restriction for variable values and variable factory return values. - Updates tests to cover successful use of
resourcevalues in variable injection scenarios. - Updates controller best-practices documentation to describe the expanded supported types.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Container.php |
Removes the remaining hard-coded type restriction for container variables / variable factory return values and updates phpdoc to mixed. |
tests/ContainerTest.php |
Drops tests that expected resources to be rejected and adds new tests that verify resource values work in variable injection. |
docs/best-practices/controllers.md |
Updates docs to state container variables/factory returns can be “any type”. |
💡 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 updates the
Containerto accept a value of any type for container variables and factory function return values. Previously, values were restricted to objects, scalars,arrayandnull, so providing any other value (such as aresource) would throw aTypeError. This removes that remaining restriction. Closures continue to be treated as factory functions rather than plain values.This includes new test cases covering
resourcevalues for container variables and factory functions. This has 100% code coverage and should be safe to apply.Builds on top of #306, #303, #302, #284, #182 and others