Answer the question
In order to leave comments, you need to log in
How to jump to a specific implementation when using the Dependency inversion principle?
The principle is to use high-level abstractions instead of concrete implementations.
Example:
interface ProductCreatorInterface
{
public function create();
}
class ProductCreator implements ProductCreatorInterface
{
public function create()
{
return new Product();
}
}
class ProductController
{
private $productCreator;
public function __construct(ProductCreatorInterface $productCreator)
{
$this->productCreator = $productCreator;
}
public function createAction()
{
$this->productCreator->create();
}
}
Answer the question
In order to leave comments, you need to log in
Since the question is not about code execution, but about the IDE, the specific answer will greatly depend on which IDE is used and even on which framework is used.
In fact, the question boils down to the ability of the IDE (on its own or through plugins) to get information related to the runtime of the application. And this, in turn, depends on whether a particular application (or the framework on which it is built) is able to provide this information in a form that the IDE can understand. If yes, you will be happy to switch to actually used implementations, if not, you will switch to abstract interfaces and look for an implementation yourself. In general, the habit of prescribing types everywhere through annotations starts to help here (in your example, this is not), but, of course, this approach has its drawbacks. you need to make sure that the specified types match the real ones. Here, in turn, a few more good habits related to the process of writing code help, but this way you can get deep into offtopic...
As an example, I will give perhaps PHPStorm in conjunction with the Symfony Support plugin in the script for working with Symfony . Since in Symfony DI container is compiled and, in addition, it generates a machine-readable representation of the container - through the plugin, the IDE gets a lot of information about what is actually used there at runtime, and navigation through the code (as well as a host of other things) becomes strong easier.
But not all IDE + framework sets are so lucky, for example, support for an application on ZF2, which you also have to deal with, does not provide this, you have to look for everything by hand. PHPStorm, of course, helps a lot here, but of course it cannot be compared with the Symfony script.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question