It would make my day to be able to have PHPStorm recognize third-party services. Has anyone figured out how to get this working yet?
I'm actually not sure how it would work if you're trying to reference another plugin's services.
It works in Craft by defining the property in the PHPDoc in
That lets PHPStorm know that there exists an AssetsService object off of
And it's not like we can add a hook for the PHPDoc so plugins can inject their own... maybe through some crazy reflection magic, but it'd be super hackey.
Absolutely, just add the app directory as a external library.
I handled it by adding a global function and singleton object similar to Craft's WebApp. All of my plugin's services are access from my custom global function myPlugin() while Craft's services continue to be started from the craft() global function. In the doc block for the new object, I specify properties for each service. Each new service must be added by hand, but all members of that service are recognized by the IDE.
This should work across all IDEs (including PHPStorm where this was developed).
In my controller, I reference my services and craft's services in the following way.
In the example above, both entries and trivia are recognized as valid objects and their methods are available for intelligent code completion.
I'm kinda late to the party here but Brandon suggested I add the technique I use to this thread.
What I do in order for PHPStorm to resolve my own
Let's say that I have a plugin called
That's what I do anyways, and it works for me.
If I had other services that I wanted type hinted, I can just add them as properties of the main service.
Note: I'm using