So I am usingSlim Framework. Not it supports Dependency Injection. Now komodo edit fails for showing autompletes for these.
Example code
$app = new Slim();
$app->helper = new Helper();
Now I should be able get suggestion for
$app->helper->...
but nothing happens.
thank you
Unfortunately a lot of PHP frameworks resolve their dependencies at runtime, which makes it impossible for an IDE to interpret your code without running it.
To get around this you could create a file that statically defines your code structure, this file is then picked up by your IDE but your project itself does not use it. For example have a look at
Whilst the author defined a specific IDE in his repo title it really isnt an IDE specific “hack”. It would work with any IDE that does some type of code intel.
I already tried something like this, but no luck yet.
@nathanr can you create sample code for me. just one function to how me?
Hi @smstoharpreet,
There is an example file in the repo: https://github.com/laravelbook/laravel4-phpstorm-helper/blob/master/_ide_helpers.php
Could you post what you’ve tried and perhaps we can assist you in figuring out where you might have gone wrong.
##My file Structure
I am creating this helper file as auto/autocomplete.php
Classes created in Library and Model folder need to be accessed in dependency injection.
Since my code was
$app = new Slim();
$app->helper = new Helper();
$app->helper->....
this $app variable does not have any helper property by default, this is how SLIM allows to give to it on the fly.
so made the file like
/**
* @property Helper $helper
*/
class Slim {}
I did try the methods too, but no luck with them as well.
Thats it.
But it did not work.
Seems we’re a bit more explicit about what format the phpdoc should be in; this works -
/*
* @property Helper $helper
*/
class Slim {};
class Helper {};
$app = new Slim();
$app->...
I’ve opened a bug to support this without phpdoc: https://github.com/Komodo/KomodoEdit/issues/317
1 Like
@nathanr i spent whole day waiting on Slim IRC
here is the solution
saved this fill as APP.php ans saved it under Library folder.
Applying the solution posted above.
I still have problem.
The autosuggest works fine when I do
use Library\App;
$app = new Library\App();
$app->helper-> // this shows autosuggest/autocomplete
but not with
use Library\App;
$app = App::getInstance();
$app->helper-> // does not show anything
please help.
I just solved this by creating just _ide_autocomplete.php file in the project root where I just created a dummy class with all the slim container key as property.
Then in my routes, in the beginning I just put a phpblock like this
/** @var Dummy $this */
My source codes are articles are in https://blog.shaharia.com/slim-php-framework-phpstorm-ide-autocompletion-solution/