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

Change Json structure #25

Open Sorien opened 9 years ago

Sorien commented 9 years ago

current one is not extensible

propesed one file silex.meta.json not pimple.json

{
    "version" : "1.0.2", //file format version
    "silex" : "2.0", // silex version
    "pimple" : {
        "dbs" : {
            "type": "container",
            "class": "Pimple\\Container",
            "values": {
                "default" : {
                    "type": "class",
                    "class": "Doctrine\\DBAL\\Connection"
                }
            }
        },
        "dbs.options" : {
            "type": "array",
            "value": ""
        }
    },

    "routes" : {
    }

    "twig-extensions" {
    }
}
CarsonF commented 9 years ago

This looks good to me :+1:

How's this for the routes section?

"routes": {
    "route name": {
         "controller" : "FooClass::barMethod", // Or some kind of signature
         "requirements": {
             "foo": "\d+"
         },
         "defaults": {
             "foo": 1234
         }
    }
}
Sorien commented 9 years ago

yep, something like that we will see in future what everything we need

CarsonF commented 9 years ago

Although I have to say I cringe at version constants in code. They are a pain for release management. Is that maintains cost worth having the version info?

CarsonF commented 9 years ago

This is going to be a major version increment for the PHP side, right?

Sorien commented 9 years ago

"version" : "1.0" .. it's just major format change just to detect why parsing fails/no routes in autocomplete and so on "silex" : "2.0", as well maybe we can use it for some optimization or disable certain functionality based on major silex version

CarsonF commented 9 years ago

Silex one, I'm fine with since they provide the constant - why not! Version....yeah it makes sense :/ Hard to be against it.

CarsonF commented 9 years ago

I have to ask: Any reason why the plugin can't have an Indexer like the Symfony2 plugin, that's makes this unneeded?

Sorien commented 9 years ago

hmm, as far as i know s2 plugin still needs dumped DI container and its a bit easier to parse xml/yaml then run throw PHP AST and search for return type from closure registering service ... short answer don't know how to do it and don't have so much free time to find it out.

Haehnchen commented 9 years ago

"dumped DI" are just one of the sources for "PHP AST" see annotations implementation, but its definitely harder in silex to do it, because of closures: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/AnnotationRoutesStubIndex.java

Sorien commented 9 years ago

just imagine this example every provider can modify session_storage_class before its used when retrieving session_storage .. there is no way how we can detect proper type without running whole code

$container['session_storage'] = function ($c) {
    return new $c['session_storage_class']($c['cookie_name']);
};
CarsonF commented 9 years ago

Yeah that makes sense. But this is only a pimple limitation. Can other things like routing not be figured out without dumping them?

(Not to discredit this structure change)

Sorien commented 9 years ago

i was planing to mix indexer and dump problem of routes from indexer is that's difficult to find out if provider was registered or not and you can use custom loaders like

$app['routes'] = $app->extend('routes', function (RouteCollection $routes, Application $app) {
    $loader     = new YamlFileLoader(new FileLocator(__DIR__ . '/../config'));
    $collection = $loader->load('routes.yml');
    $routes->addCollection($collection);

    return $routes;
});
Sorien commented 9 years ago

@Haehnchen maybe you will know, is there any way how to implement custom stub indexer (StringStubIndexExtension) for plugin?

Haehnchen commented 9 years ago

t think you can use EnumeratorStringDescriptor: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/RoutesStubIndex.java

moreover if you need the routes itself. they are already inside the symfony2 plugin index

Sorien commented 9 years ago

https://github.com/Sorien/silex-pimple-dumper/pull/6