从 Spaghetti 代码迁移到 Symfony 2

发布于 2024-12-13 15:15:24 字数 198 浏览 0 评论 0原文

我刚刚在美国公司找到了一份工作,并且继承了一堆令人讨厌的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-12-20 15:15:24

首先,你有没有问过他们是否会让你重构应用程序?您可以基于以下方面构建业务案例:

  • 能够以较低的成本维护软件的未来
  • 更容易向项目介绍其他开发人员
  • 更容易添加新功能

完整的重构可能并不像正如您所想象的那样复杂或耗时,并且可以在维护旧应用程序的同时并行完成。

现在,按照你的建议去做有点棘手。您必须考虑以下事项:

  • 能否在现有数据库结构上使用 ORM 取决于它的设计程度。
  • 许多 php4 代码无法在 php5 上运行,您最终可能会更改大量代码、引入错误等。
  • 需要一些自定义代码才能在两个代码库上集成会话。

如果上述几点不是问题,您可以将 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:

  • Ability to maintain the software going forward at a lower cost
  • It'll be easier to introduce other developers to the project
  • It'll be easier to add new features

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:

  • Being able to use an ORM on the existing database structure depends on how well it's designed.
  • A lot of php4 code will not work on php5 and you may end up changing a significant amount of code, introducing bugs, etc.
  • Some custom code will be required in order to integrate the session on both code-bases.

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!

空袭的梦i 2024-12-20 15:15:24

首先,将定制的前端控制器作为这些平面文件的前端。

您可以使用 mod_rewrite 将旧网址重定向到新的前端控制器。

RewriteRule ^/?(.*) /index.php/$0
# this shall work in .htaccess (/paths) and in httpd.conf (non slashed local paths)

然后可以通过 $_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.

RewriteRule ^/?(.*) /index.php/$0
# this shall work in .htaccess (/paths) and in httpd.conf (non slashed local paths)

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.

浅唱々樱花落 2024-12-20 15:15:24

我的建议是将其分解为步骤。通常,管理层会比一次性的大成本更容易接受一系列的小成本。在迁移到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文