将Brownfield PHP Webapp转换为Zend Framework [英] Converting a Brownfield PHP Webapp to Zend Framework

查看:80
本文介绍了将Brownfield PHP Webapp转换为Zend Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在考虑将我们的PHP Webapp从不使用任何框架(这使我们丧命)转换为使用Zend Framework.由于应用程序的大小,我认为从头开始不会成为管理的可行选择,所以我想开始研究如何使用Zend Framework从当前站点结构缓慢地转换为一个站点,但是没有一个有关此过程的很多信息.

We're thinking of converting our PHP Webapp from using no framework (which is killing us) to use Zend Framework. Because of the size of the application I don't think starting from scratch is going to be a viable option for management so I wanted to start researching how to slowly convert from the current site structure to one using Zend Framework but there isn't a lot of information on this process.

到目前为止,我的计划是将当前代码库转储到Zend应用程序的public/目录中,解决许多我确定会出现的问题,然后开始一次重写一个模块.

So far my plan is to dump the current code base into the public/ directory of the Zend Application, fix the numerous problems that I'm sure this will crop up and then start rewriting modules one at a time.

过去有没有人有这样做的经验,它对您有什么帮助?

Has anyone had experience doing this in the past and how did it work out for you?

推荐答案

我现在已经做了一些.对我来说,最有效的方法是将ZF放在旧应用程序周围,因此所有请求都通过ZF进行.然后,我有一个旧版"控制器插件,该插件检查ZF是否可以满足该请求,如果不能,则将其发送到旧应用程序:

I've done a few of these now. What worked best for me was putting ZF 'around' the old app, so all requests go through ZF. I then have a 'Legacy' controller plugin, which checks whether the request can be satisfied by ZF, and if not, sends it to the old app:

class Yourapp_Plugin_Legacy extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
        if (!$dispatcher->isDispatchable($request)) {
            // send to the old code...
        }
    }
}

然后将请求发送到旧应用程序的确切方式取决于它的实现方式.在一个项目中,我检查了请求,从请求的旧代码中确定了该文件应该进入的文件,然后要求将其放入.听起来这可能适合您.在另一个项目中,我的解决方案是将所有这些请求路由到ZF项目中的LegacyController,后者运行旧代码以获取生成的HTML,然后从新项目中将其呈现在Zend_Layout中.

exactly how you then send the request to your old app depends a bit on how it is implemented. In one project, I examined the request, determined what file from the old code the request would have gone to, and then required that in. It sounds like this might be appropriate for you. In another project my solution was to route all these requests to a LegacyController in the ZF project, which ran the old code to get the resulting HTML and then rendered it inside the Zend_Layout from the new project.

此方法的优点是,您可以在重写旧应用程序的各个部分时逐步引入ZF模块,直到达到ZF可以满足100%请求的程度.另外,由于ZF项目已在运行旧代码之前初始化,因此旧代码可以使用ZF自动加载器,因此您可以开始使用以ZF风格编写的模型替换旧代码中的类,并让两者该应用的各个部分.

The advantages of this approach are that you can gradually introduce ZF modules as you rewrite parts of the old app, until you reach the point where 100% of requests can be served by ZF. Also, since the ZF project has initialized before your old code is run, your old code can use the ZF autoloader, so you can start replacing classes in the old code with models written in a more ZF-style, and have them used by both parts of the app.

这篇关于将Brownfield PHP Webapp转换为Zend Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆