tags:

views:

95

answers:

2

My team have to maintain a large php application that was very poorly written. It is a mix of html, javascript and SQL on top of a large poorly designed database (ex. it has a table with few hundreds of columns). The only advantage of the codebase is that it works.

We are constantly bug fixing and rewriting parts of it.

I would like to give a structure to the rewrites we do, so I've though about integrating an mvc framework in to the codebase. Could you suggest any good framework for environment?

Here is a list of things that the I would expect from such framework:

  • The API must be very stable. We can't afford to rewrite the code on each release.
  • Custom session management or at least working on standard $_SESSION[] (To be able to talk with old code).
  • Custom authentication.
  • Using the raw SQL should be well supported (The database is hard to represent in terms of objects).
  • It shouldn't assume that I will have a table per controller.
+2  A: 

I suggest Zend Framework for this purpose because it is a glue framework. With ZF you are not forced into the harness of how the framework expects you to work with it. You can pick what you want and gradually replace your legacy code with code from ZF. It also supports all the things you mentioned.

In addition, I suggest to run the various QA Tools found at phpqatools.org to support you in debugging and refactoring.

Framework comparisons

Gordon
What with api stability? I've heard that there was major changes between 1.0 and 1.7
Piotr Czapla
1.0 is no longer relevant. Current release is 1.9 with 1.10 currently in testing. The API is stable. There will be some major changes when 2.0 is here, but afaik there is no ETA yet.
Gordon
Zend is probably your best bet, also because (from my understanding of it, I'm comparing frameworks myself right now) it will not require you to immediately rewrite all of the spaghetti in order to conform with its architecture. Of all the frameworks around, Zend is probably the best candidate for allowing a slow transition.
Pekka
@Pekka that's actually what I meant with *you are not forced into a harness* :) Might not have been too clear. Thanks for rephrasing it.
Gordon
@Gordon: I overread that part, sorry :)
Pekka
+1  A: 

I'm echoing Zend just to list how it fits your specific requirements:

  • The API must be very stable. We can't afford to rewrite the code on each release.

As mentioned, the API tends to be stable between minor releases. Major releases with changes shouldn't be hard to integrate.

  • Custom session management or at least working on standard $_SESSION[] (To be able to talk with old code).

Zend_Session does exactly what you want. The default session store is $_SESSION to which Zend adds a namespace concept. Your existing code should be fine, and any new code can use the Zend object to ensure there are no variable name overlaps.

  • Custom authentication.

Zend_Auth has a few authentication backends, but it is designed to allow you to implement your own auth.

  • Using the raw SQL should be well supported (The database is hard to represent in terms of objects).

Zend_DB and implements the table gateway pattern which will allow you to access the data via object; however, you can also just use SQL directly and get the results as arrays.

  • It shouldn't assume that I will have a table per controller.

Zend_Controller and the rest of Zend's MVC implementation make no assumptions about the Model, leaving that completely up to you. I'm sure some people don't like that, but it is the one area of MVC design that varies greatly from project to project - so that's left completely to the developer. You could extend some of the DB classes, or just use the existing DB access code.

That's an example of the pick-and-choose mentality of the Zend Framework. You really can use any of the library by itself. That should work well with your project. For example, you could use Zend_View without the rest of the MVC classes just to move your presentation into templates. Or just use Zend_Auth to replace the existing Auth system. With Zend you can slowly move your project into a more structured state, little by little.

Tim Lytle