I’m testing PhPStorm with Slim3 and ofcourse this IDE is fantastic, but I’m stuck with a couple of nasty ‘method not found’ issues
- Statements like $this->view->render($response… (using Twig), the ‘view’ part is seen as a magic method by PhpStorm. Tried Symfony and Laravel-plugins and also the PHP-DI plugin, but no result
- Using Eloquent gives some ‘xxxx’ methods not found. FI the ‘create’ method is found so that you can do something like ‘Region::create’, but ‘Region::find’ gives in PhpStorm method not found. All I have in my Region Model is ‘use Illuminate\Database\Eloquent\Model’ where Region extends Model.
Did I forget some setting in PhpStorm or is there some other magic I should be aware of?
Cheers
Hey there!
From my experience, there isn’t much you can do about referencing $this-> from closure-style actions in Slim 3; the Pimple Instance doing lookup duties has enough abstraction between your services and the place you’re calling them from that, outside a bunch of @property declarations and an @var to declare what $this is, you’re probably not going to get what you want.
That said, if you’re declaring your controllers/actions as services and referencing those services’ names in your routes file, you can constructor-inject (with typehints etc.) everything you need, such that when you hit __invoke() (or another method name, using the service:method syntax at the router level) $this will be your controller/action class, with your freshly constructor-injected parameters. And of course, 'Storm has no issues with those
Not the greatest for tiny controller methods where you’d rather just inline 'em as closures, but it’s what I’ve done to get non-trivial route dispatching, to a high degree of success.