This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add check to DI to see if we have a class to instantiate #4790
Closed
nickpeirson
wants to merge
4
commits into
zendframework:master
from
nickpeirson:DIClassExistenceCheck
Closed
Add check to DI to see if we have a class to instantiate #4790
nickpeirson
wants to merge
4
commits into
zendframework:master
from
nickpeirson:DIClassExistenceCheck
Conversation
This file contains 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
Also added a special case for when we're mistakenly trying to instantiate an interface
please provide unit test. |
Add a unit test that covers the exception being thrown. Working through it it seems like the underlying problem could be with the definition produced by Zend\Di\Definition\CompilerDefinition, as I can't reproduce it just using the runtime definition. That being said, with the current state of the definition compiler this is a problem (I don't have time right now to dig into the compiler, but I may come back to it in the future), however this mitigates it so I feel it's worth adding. |
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Di |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove @Package
weierophinney
added a commit
that referenced
this pull request
Jul 19, 2013
Add check to DI to see if we have a class to instantiate
weierophinney
added a commit
that referenced
this pull request
Jul 19, 2013
- Use sprint for exception message string interpolation - No need for escaping namespace separators when class names are uppercase
ghost
assigned weierophinney
Jul 19, 2013
weierophinney
added a commit
to zendframework/zend-di
that referenced
this pull request
May 15, 2015
…DIClassExistenceCheck Add check to DI to see if we have a class to instantiate
weierophinney
added a commit
to zendframework/zend-di
that referenced
this pull request
May 15, 2015
- Use sprint for exception message string interpolation - No need for escaping namespace separators when class names are uppercase
weierophinney
added a commit
to zendframework/zend-di
that referenced
this pull request
May 15, 2015
weierophinney
added a commit
to zendframework/zend-di
that referenced
this pull request
May 15, 2015
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Currently the DI container throws a fatal error when trying to instantiate a class that doesn't exist or, more usually, when DI tries to instantiate an interface.
The fatal error looks like:
This PR changes the behaviour to check for the existence of the of the class before trying to instantiate it and throws and exception accordingly. This results in a much more developer friendly backtrace allowing a developer to identify the problem more quickly and spend less time debugging. As we see this most commonly when we've missed a type preference for an interface I've also added a case for when the class to be instantiated is in fact an interface, to add clarity to the thrown exception.