Rovak / KJSencha

Ext-JS / Sencha Touch Integration Module for Zend Framework 2
Other
24 stars 15 forks source link

ServiceLocator services as RPC #4

Closed Ocramius closed 11 years ago

Ocramius commented 11 years ago

ServiceLocator services as RPC (WIP)

Current logic

Currently, APIs are simple mappings from FQCN to published APIs via ExtJs Direct.

For example, mapping a directory that contains following classes under namespace MyStuff.example:

Allows usage of following (js-side):

While the concept works very well for simple use cases that don't involve dependencies, this approach doesn't fit the current ZF2 philosophy nor complex approaches, since the FQCN itself does not define what an object looks like.

New logic

My idea is to migrate everything to service IDs. Instantiation of the services themselves would still be based on the main ServiceLocator, so it would work out of the box.

For example, defining following services:

And mapping them as following:

return array(
    'my_test_service',
    'another_service',
    'My\FQCN\Named\Service',
    'yet.another.naming.convention',
    'test1' => 'my_test_service',
    'test2' => 'another_service',
    'test3' => 'My\FQCN\Named\Service',
    'test4' => 'yet.another.naming.convention',
);

Would give access (js-side) to following direct methods:

This also defers all the instantiation of direct services to the service manager, giving us much more power

Automatical name conversions

I think it would be still possible to use \ and . as namespace separator in the PHP to JS conversion, though I'd prefer to have the end user define it manually. Anyway, this method removes any "grouped" namespacing, by giving direct alias to multiple aliases for a single user to a service.

Ocramius commented 11 years ago

Closing since the proposal was accepted