从 Spaghetti 代码迁移到 Symfony 2
我刚刚在美国公司找到了一份工作,并且继承了一堆令人讨厌的 php 4 平面文件。我想迁移到 Symfony 2,但我无法获得重构整个事情的许可。
有人对将项目的小部分或部分迁移到 Symfony 2 有什么建议吗?也许我可以拥有一个包含整个旧代码库的目录,然后仅使用 Symfony 2 中的路由来获取旧的平面文件?
如果有人有任何建议,我很想听听。
I just got a job back in corporate america, and I have inherited a nasty bunch of php 4 flat files. I want to migrate to Symfony 2, but there is no way I'll get permission to re-factor the whole thing.
Does anyone have any suggestions for migrating small parts or sections of a project to Symfony 2? Perhaps I could have a directory with the entire old code base and start by only using the routing in Symfony 2 to grab the old flat files?
If anyone has any suggestions I'd love to hear them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,你有没有问过他们是否会让你重构应用程序?您可以基于以下方面构建业务案例:
完整的重构可能并不像正如您所想象的那样复杂或耗时,并且可以在维护旧应用程序的同时并行完成。
现在,按照你的建议去做有点棘手。您必须考虑以下事项:
如果上述几点不是问题,您可以将 php4 结构添加到 web 文件夹中,以便可以直接访问它们,并在 Symfony 中构建每个屏幕时开始一一替换路由。
这些建议非常切合实际。这实际上取决于您的应用程序有多复杂以及它到底有多混乱。
祝你好运!
First of all, have you asked whether they'll let you refactor the application? You can build a business case based on:
A full re-factor may not be as complicated or time consuming as you envision, and it can be done in parallel while maintaining the old app.
Now, doing what you suggest is a bit more tricky. You have to consider the following:
If the above points are not an issue, you may get away with adding the php4 structure to the web folder so that they can be accessed directly, and start replacing routes one by one as you build each screen out in Symfony.
These suggestions are very contextual. It really depends on how complex your application is, and how messy it really is.
Good luck tho!
首先,将定制的前端控制器作为这些平面文件的前端。
您可以使用
mod_rewrite
将旧网址重定向到新的前端控制器。然后可以通过
$_SERVER['PATH_INFO']
在 index.php 中检索路径。从前端控制器,您可以处理一些细粒度的逐步重定向到您希望移动到的任何固定解决方案。对于您想要保留旧功能的 URL,某些
include("./".$_SERVER['PATH_INFO'])
就可以解决问题。First of all, put a custom made front controller as a front-end to those flat files.
You can redirect old urls to the new front controller with
mod_rewrite
.Paths can then be retrieved in index.php trough
$_SERVER['PATH_INFO']
From the front controller you can handle some fine grained gradual redirections to any canned solution you wish to move to. For the URLs for whom you want to preserve old functionality, some
include("./".$_SERVER['PATH_INFO'])
shall do the trick.我的建议是将其分解为步骤。通常,管理层会比一次性的大成本更容易接受一系列的小成本。在迁移到 Symfony2 之前,我会专注于清理代码并准备好 PHP5。
一旦代码干净,将 Symfony2 集成到您的项目中应该非常容易。
My advice is to break it out into steps. Often management will accept a series of small cost much more readily than a one time big cost. I'd focus on getting the code cleaned up and PHP5 ready before migrating to Symfony2.
Once the code is clean, integrating Symfony2 into your project should be pretty easy.