tags:

views:

57

answers:

4

Hi,

I've made several php scripts as a plugin for one large framework. My scripts use its libraries quite often. Now someone who is using another platform, with its own libs and so on (probably just as powerful as the framework i use) wants to call functions in my scripts.

What's the best way to make my scripts callable from another framework?

  • the other person just include()s the script files he needs, so my scripts call my framework's libraries, also meaning that both frameworks need to be installed at the same server
  • i make my functions callable through web services (probably incurring loss of speed, but separation of frameworks is possible)
  • rewriting my functions to his framework...

Does anyone have an opinion based on attempts they made as to which is the nicest solution when one of the platforms decides to upgrade, for instance?

Cheers!

+1  A: 

To make your code portable across frameworks you could write an additional layer of abstraction - a framework layer. You then have an include for each framework you support. Which file is included could be determined at runtime by detecting the framework. Wherever you call a function in the underlying framework, call your own function instead, and this function then calls the appropriate function in the framework.

You could develop this as an interface and create a class for each framework that implements this.

w3d
true, but that would mean even more rewriting work :-) and the easier solution to that would be the webservice approach. Thanks for the suggestion!
Tominator
+2  A: 

From a performance, maintainability and readability standpoint, it's best to pick one "framework" and stick to it (for the application). I put framework in quotes since I'm also using it in the context of a set of libraries.

Each one of your solutions will work, but I think that the best one would be #3 if it's for a single application. #2 will work better if they are discrete applications (since it loose couples the applications from each other).

Personally, I would suggest picking one framework for an application and sticking to it. So #3 would be my suggestion (without knowing if they are separate applications or not)...

ircmaxell
They are separate applications, so the webservice approach would be the easiest and cleanest too. If i choose to rewrite, i'd have to maintain both versions and that would be a bit dangerous. So i'll go with the webservice approach, thanks for the rationalisation!
Tominator
+1  A: 

Assuming you were willing to give them full access to your libraries (which are usually not world readable by default) you'd be asking them to load and use all the overhead of both frameworks, which could be a real performance killer. Like loading Jquery and Prototype, you can do it, but it's not terribly smart.

Going the webservices route solves your security issues, separates the two frameworks, opens you up to use by others in the future (regardless of their framework/platform) and will likely save time.

bpeterson76
Indeed, it provides the more clean separation of the options
Tominator
+1  A: 

@ircmaxell makes a good point, however I would extend that if you have to do this, and you have the luxury of PHP 5.3, use namespaces with any extensions or broker code between the frameworks.

Andrew Sledge
unfortunately i don't have that luxury yet, but i'll keep it in mind!
Tominator