开发者

What php framework to use on top of spaghetti codebase?

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 c开发者_如何学JAVAontroller.


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

  • http://www.phpframeworks.com/
  • http://php-frameworks.net/


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜