Sorien / silex-idea-plugin

Idea plugin for Silex Framework - plugin is not compatible with PHPStorm 2016.2
MIT License
26 stars 8 forks source link

Resolve extend anonymous function parameter #7

Closed CarsonF closed 9 years ago

CarsonF commented 9 years ago

Would be nice to have $twig resolved to Twig_Environment. I know this can be type hinted, so this is a low priority.

$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new TwigExtension($app));
    return $twig;
}));
Sorien commented 9 years ago

at first i'd like to cover Pimple autocomplete than we will see, maybe routes/twig/translations and so on

CarsonF commented 9 years ago

I completely agree. My Java is rusty and I have no knowledge of the IDEA SDK, but I could help with the Silex Provider side.

routes could be dumped to a json file for the plugin to pick up?

For twig are you thinking {{ app.foo }} completion?

Sorien commented 9 years ago

if you want to try it Silex Plugin 0.9.6

CarsonF commented 9 years ago

Works beautifully!

I see that you've also resolved the second parameter $app, I like that. Along those lines should $app be resolved elsewhere?

$app['twig'] = $app->share(function ($app) {
...
});

I think $app->share would be the only use case. It isn't needed for $app->protect and we probably can't distinguish for just a non-shared closure $app['foo'] = function($app) {}. Although that would pose problems for Pimple 2.x/3.x since services are shared by default.

Could you distinguish by checking if they are being assigned to a Pimple instance, and then resolve the $app parameter for the closure?

Sorien commented 9 years ago
Could you distinguish by checking if they are being assigned to a Pimple instance, and then resolve the $app parameter for the closure?

Yes, i'll do it that way...

from reading docs, these use-cases are not resolved (I hope I didn't forget anything)

Pimple 1.x

$app[''] = $app->share(function ($c) { //resolve $c
});

Pimple 1x & 3

$app[''] = function ($c) { // resolve c, based on assignment to pimple container ($app)
};

$app->raw('')->; //autocomplete inside '' and -> 

Pimple 3

$app[''] = $app->factory(function ($c) { // resolve $c
});

and

$app['foo'] = $app->share(function () { return new \Pimple(); });
$app['foo']['']->; //autocomplete '', ->, 

if I'm missing something just let me know :)

CarsonF commented 9 years ago

Yeah looks good!

I would be careful with raw(), doesn't that return the factory closure instead of the instantiated service?

Ah yeah I was thinking about sub-containers too, I didn't want to overwhelm you though :) I have a PR coming for the PHP service provider tonight

Sorien commented 9 years ago
I would be careful with raw(), doesn't that return the factory closure instead of the instantiated service?

Yeah, you are right ...

CarsonF commented 9 years ago

But the service name could still be resolved

Sorien commented 9 years ago

everything except sub containers should be solved ... i will release 0.9.6