These are chat archives for ppi/framework

16th
Nov 2015
Matthieu Napoli
@mnapoli
Nov 16 2015 17:27
hi @dragoonis
Paul Dragoonis
@dragoonis
Nov 16 2015 17:37
@mnapoli welcome :)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:07
thanks :) ready to discuss container-interop if you have time
Paul Dragoonis
@dragoonis
Nov 16 2015 18:07
I solved interoperability routing in PPI 2.1 by using a chain-router (aka composite route)
foreach($this->routers as $router) { $router->match(); }
Matthieu Napoli
@mnapoli
Nov 16 2015 18:08
yep
Paul Dragoonis
@dragoonis
Nov 16 2015 18:08
I think a composite-container would be good too.
This would allow each module to have its own container. Zend\SM, Aura\Di ..etc
Given the current state of container-interop, how would you implement this ?
Matthieu Napoli
@mnapoli
Nov 16 2015 18:09
yeah that's an idea that's been discussed with @moufmouf, see for example: https://github.com/thecodingmachine/root-container
Paul Dragoonis
@dragoonis
Nov 16 2015 18:09
Invite @mouf here?
why not, I don't know if he's available
there is a problem to that solution though:
it doesn't allow (from what I've tried) to extend definitions from other containers
Paul Dragoonis
@dragoonis
Nov 16 2015 18:12
interesting.
Matthieu Napoli
@mnapoli
Nov 16 2015 18:12
for example if you want to let modules register twig extensions, you want to have a collection/array/list in the container. The list starts empty in the root module (i.e. the framework's module). Then each module should be able to add extensions to the list. If each module has a separate container, then there's no way to modify the definitions
I'm not really clear sorry
the list/collection problem is solved in Symfony and Laravel using tags
Paul Dragoonis
@dragoonis
Nov 16 2015 18:12
I understand you.
Matthieu Napoli
@mnapoli
Nov 16 2015 18:12
in PHP-DI it's using arrays
since accross containers you can't edit definitions, then solving this problem becomes hard… And it removes one main feature of modules.
Paul Dragoonis
@dragoonis
Nov 16 2015 18:13
Interesting.
What if you wanted to have 1 unique type of container.
Module A [ZF container]
Module B [Aura DI]
Module C [ZF]
Module D [Aura DI]
Module A and C can cross-communicate because they’re inside the same container.
I don’t like this idea a solution, but it’s a workaround.
Matthieu Napoli
@mnapoli
Nov 16 2015 18:14
yep
another approach to that problem is to have interoperability for container definitions. It's been discussed on the FIG mailing list. But it's hard to implement because either you standardize basic features that all container support and in that case you don't solve the problems of collections and extending/decorating existing entries, either you standardize all features but many containers couldn't be compatible, and anyway all containers have different solutions for the same problems (e.g. tags vs arrays, etc.)
see https://github.com/container-interop/compiler-interop also (didn't lead anywhere yet)
Paul Dragoonis
@dragoonis
Nov 16 2015 18:17
Yep. I’ve seen container-interop, and familiar with PSR-11.
Matthieu Napoli
@mnapoli
Nov 16 2015 18:18
this link is different ;) it's "compiler interop"
Paul Dragoonis
@dragoonis
Nov 16 2015 18:18
ah
Matthieu Napoli
@mnapoli
Nov 16 2015 18:19
but it was only meant for compiled containers… the landscape of containers is so diverse, it's a really complex problem
Paul Dragoonis
@dragoonis
Nov 16 2015 18:19
What we do in PPI so far is deliver the RAW container to users, and have a common way to returning this back to PPI to process.
object mediation instead of abstraction
Core challenges still remain though.
Matthieu Napoli
@mnapoli
Nov 16 2015 18:21
yeah. Once that is solved, add Puli, middlewares/chained routers (as you mentioned) and we'll see framework agnostic modules
Paul Dragoonis
@dragoonis
Nov 16 2015 18:21
yes. PPI is driving this effort. I will bring chained routers to FIG after PSR-6 finished (few weeks now) :)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:23
interesting! do you have a link to have a look before then? ;)
I'm curious
Paul Dragoonis
@dragoonis
Nov 16 2015 18:23
Yes, I’ve done talks in many countries about it :)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:25
interesting, so you implement Symfony's interface I see. You are not looking at PSR-7 middlewares?
Paul Dragoonis
@dragoonis
Nov 16 2015 18:25
I created this before PSR-7 existed ;)
@dannym87 is in process of upgrading our Request object to use Symfony-Bridge to be PSR-7 compliant.
Right now we have hacked up, but compliant version of PSR-7 for Request/Response
Matthieu Napoli
@mnapoli
Nov 16 2015 18:29
:+1: I've been playing lately with routers as middlewares (e.g. https://github.com/stratifyphp/router/blob/master/src/Router.php#L52). It allows to combine them, for example here is a "prefix router" that will dispatch to other routers based on a prefix: https://github.com/stratifyphp/router/blob/master/src/PrefixRouter.php I can then make an application where everything that starts with /api/ is routed to an authentication middleware, then another router that dispatches API endpoints, and everything that is not under /api/ is the public application (so dispatched to another router that renders the public website)
pretty fun stuff ;)
Paul Dragoonis
@dragoonis
Nov 16 2015 18:30
It seems like we’re working on the same thing, but separately :)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:32
I'm more playing than doing anything serious (unfortunately), I don't have enough time to follow on all these things
Paul Dragoonis
@dragoonis
Nov 16 2015 18:33
The journey of a thousand miles begins with one step - Lao Tzu :-)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:33
:+1:
Paul Dragoonis
@dragoonis
Nov 16 2015 18:34
So .. containers :)
Matthieu Napoli
@mnapoli
Nov 16 2015 18:37
yep, there no magic solution that I know of you want to use container-interop and modules
what I would advise is to use ContainerInterface wherever possible, so that users can replace the container. But choose one default container, and have all official modules be implemented with it
That's what Slim did: their TwigServiceProvider, DoctrineServiceProvider, etc. are all based on Pimple
for the PHP-DI integration I had to re-create such modules
(as long as the framework itself isn't coupled to the container, it's just the module system that needs to be adapted in order to support a different container)
Paul Dragoonis
@dragoonis
Nov 16 2015 18:43
okay, good
Paul Dragoonis
@dragoonis
Nov 16 2015 18:57
ServiceManager and ModuleManger have some coupling there. We want to break away from that as you can understand why.
I think line 54, would be changed to add custom listener, to put module’s definitions into container-interop
thoughts?
Matthieu Napoli
@mnapoli
Nov 16 2015 19:02
sorry I'm not familiar with Zend's ServiceManager: what are service listeners?
Paul Dragoonis
@dragoonis
Nov 16 2015 19:02
It’s just ZF EventManager component :)
Matthieu Napoli
@mnapoli
Nov 16 2015 19:05
ah ok so each module would receive the service manager/container and add its services to it?
Paul Dragoonis
@dragoonis
Nov 16 2015 19:05
I believe so!
double register, maybe ? (with cache)
This way, you have single DiC, but can use native one within your module.
Create Aura Definitions in Module A, return to PPI, which convert to ZF2 ServiceManager. Thoughts?
PPI Core = ZF2 (for now)
Module A [ ZF2 Definitions ] (no convert needed
Module B [Aura\Di] Convert to ZF2 definitions
Matthieu Napoli
@mnapoli
Nov 16 2015 19:10
oh converting definitions would be a huge task I think. Maybe it would work though, I admit I haven't thought about it
Paul Dragoonis
@dragoonis
Nov 16 2015 19:10
“a use task” ?
Matthieu Napoli
@mnapoli
Nov 16 2015 19:10
sorry :/ a huge task ;)
Paul Dragoonis
@dragoonis
Nov 16 2015 19:11
With routers, i decided NOt to convert to single route type, and create small wrappers to single interface.
but yes, routers are isolated/decoupled by design.
for DiC I don’t think having isolated DiC is a good thing.
Paul Dragoonis
@dragoonis
Nov 16 2015 19:17
@mnapoli idea!!!
What if each child Container had a copy of the global container. So you could access the global container when you need a service not defined within your own Module ?
@mnapoli what did you mean by “extend another service” ?
Each child container is given global container as $container arg ?
‘my.service’ => function($globalContainer) {
    $o = $globalContainer->get(‘service.from.other.container’);
    return new Service($o);
}
Matthieu Napoli
@mnapoli
Nov 16 2015 19:20
what you describe is the "delegate lookup feature" yes (without it each module cannot use services defined in the application or other modules)
so yes it's necessary
Paul Dragoonis
@dragoonis
Nov 16 2015 19:20
I approve of Delegate :)
Matthieu Napoli
@mnapoli
Nov 16 2015 19:21
but it doesn't allow to extend: for example the root module could define an EventDispatcher, and then each module would need to register listeners to it
in PHP-DI that's these bunch of features: http://php-di.org/doc/definition-overriding.html
Paul Dragoonis
@dragoonis
Nov 16 2015 19:22
is “extend” common use of DiC ?
I only see people using get/set/has/del() on containers
Matthieu Napoli
@mnapoli
Nov 16 2015 19:23
same for collections: e.g. the "Twig module" defines an initial list of "Twig extensions". Then there's the (for example) "Google Analytics module" that wants to define a ga() Twig function: it needs to add a new entry to the twig_extensions collection
in Symfony that's what tags and compilation passes are for
in Laravel too
Paul Dragoonis
@dragoonis
Nov 16 2015 19:23
Right.
Matthieu Napoli
@mnapoli
Nov 16 2015 19:24
with tags instead of defining a list and adding items to it, you tag a service. But the result is the same, it allows to manage collections of services
Paul Dragoonis
@dragoonis
Nov 16 2015 19:24
okay. I understand
Matthieu Napoli
@mnapoli
Nov 16 2015 19:24
so in those cases, you don't want to replace the previous entry, you want to "extend" it (by adding item to it, or decorating the service for example). If you chain containers that don't share definitions, it's not possible i'm afraid
Paul Dragoonis
@dragoonis
Nov 16 2015 19:25
kind of AOP decoration, maybe :)
Paul Dragoonis
@dragoonis
Nov 16 2015 23:16
I’m making a screencast - I’m wondering what people want to see ? :)