Page 1 of 1

'glue' patterns for wiring together various php frameworks

Posted: Fri Dec 04, 2009 12:56 am
by Dave M
hey php peops --

noob question (just migrated to open sauce from many years as M$ dev. Finally jumped in the pool.):

Im trying to come up with a decent and simple pattern for 'gluing' together various php frameworks. Mostly I'd like to be able to swap them out if needed later on.

For now Im looking at using say, OWASP php, phpGroupware, outlet ORM, phpMvc, and phpGacl or flow3. Of course I need write my code to wire/glue all these FWs together to play nice with one another...

....obviously Facade pattern comes to mind. Write an interface/facade module for each framework to site between my code and the FWs to insulate from future changes in the frameworks. But, that seems like lots of work to consolidate each framework, considering I really don't even know the FWs that well myself just yet. (and I may get 2 weeks into writing a facade and swap/test/discover/change to an alternate framework or two while Im in the 'php noob' stage)

IOC/DI will probably come in handy at some point, thus flow3 framework, mimicking Spring. (If it breaks out of alpha, beta, ga-ga land, that is.)

What patterns/designs/best practices are you all currently using to ease the pain of:
1. having so many great choices of available FWs? (unheard of in M$ world. It's usually RYO/DIY all the way there)
2. organizing the directories off root with them (lots of name scheme clashes in Asp classic includes)
3. gluing them together with some kind of harmony and simplicty.

just curious.

Re: 'glue' patterns for wiring together various php frameworks

Posted: Tue Dec 22, 2009 6:04 am
by AntonioCS
Why don't you just use one framework?

Re: 'glue' patterns for wiring together various php frameworks

Posted: Tue Dec 22, 2009 12:21 pm
by Christopher
Adapter pattern.

Re: 'glue' patterns for wiring together various php frameworks

Posted: Wed Dec 23, 2009 8:06 am
by josh
LOL @ adapter pattern
yeah.. question too generic

Re: 'glue' patterns for wiring together various php frameworks

Posted: Wed Dec 23, 2009 12:56 pm
by Christopher
Not meant to be funny, nor do I think the question is too generic.

The solution to the problem presented is to define common interfaces and then place the various components behind those interfaces. That is the Adapter pattern.

Re: 'glue' patterns for wiring together various php frameworks

Posted: Wed Dec 23, 2009 2:31 pm
by josh
Well yeah it is, but "glueing" is different, ex. if you are using Doctrine for data persistence, and Zend for MVC, wouldn't that still be a "glue" (regardless of wether or not you wrapped the API). I think this question is "unanswerable" because "glue" is just a buzzword (although an adapter would be the best way of "gluing", the OP has not even told us what kind of frameworks he is gluing, the most effective strategy will depend on the problem at hand). For instance using Doctrine for persisting models and Zend for MVC, an adapter is not as imminently needed, vs if you were "melding" two different data persistence frameworks (an adapter would be more imminently called for)

The buzz word "glue" in PHP is generally used to refer to something completely different, its used to refer to the fact an architecture could have independent sub-systems, like mysql & couch db, or a cache subsystem like memcache... so basically in this context "glueing" means to use existing "machine code" programs because they will outperform any PHP based solution

Re: 'glue' patterns for wiring together various php frameworks

Posted: Thu Dec 24, 2009 3:57 am
by VladSun
Isn't it a Facade pattern indeed? I think, the Adapter pattern is used when a specific interface to a single object is needed (and it's usually 1:1 mapping), while the Facade pattern is used to create an interface to a group of objects that define a "system" (and it's usually there is a little, even no mapping).

Re: 'glue' patterns for wiring together various php frameworks

Posted: Thu Dec 24, 2009 5:56 am
by Darhazer
Facade pattern as defined in [Gang of Four] is a way to present a simplified interface to a system. In that interface single method can call a lot of methods in the system behind the facade. The facade can be some kind of adapter, where the systems behind it have common functionality with different interface, and you create a facades with the same interface (each other), which hides the different interfaces of the systems.

Adapter pattern is used when you have one interface and you need to use another one. Usually it means "morphing" one object in another, but still it's possible to have adapter with one interface, which uses 2 or more classes, that actually provide that functionality. And there is a mapping indeed.

So I have to agree with VladSun, that Facade is more appropriate in the case.

Another pattern that comes in mind is a bridge - separate the abstraction (your code) and the implementation (the specific framework components)

Re: 'glue' patterns for wiring together various php frameworks

Posted: Thu Dec 24, 2009 7:13 am
by josh
Exactly question is soo open ended.

You could even just use the existing API, "hard code" it... I mean if the framework in question is as "hefty" as zend framework, it may not be feasible to even attempt to change the API at all, it is already extremely stable as is.