[5.8] Updated the container for better PSR-11 ContainerInterface compliance #25678
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.
I think the current implementation of PSR-11 breaks the contract. The interface only describes the has() and get() methods but the has() returns false on autowired classes.
The docs for PSR-11 for the has() method state:
Because the container can autowire classes it think it should return true in case of a class that it can autowire because it's able to return an entry for the given identifier even if it's unknown.
For example I've made a composer package that can run independently from any framework, as long as you provide a PSR-11 compliant Container. Currently the only way to get my code to work with the Laravel Container is to use the make() method as I refuse to bind hundreds (if not thousands) of classes from the multiple Laravel repositories I maintain and their respective required composer packages. As the make() method is not defined in the PSR and I can't use the has() method, this means the Laravel Container breaks the contract and I have to add some Laravel specific code.
I've made a simplified version of a Factory class to state whats wrong with the current implementation
After the made changes the Factory doesn't require the Laravel specific code and will look like this: