I have a large existing web application that isn't built on Symfony. It badly needs some improvements that are too difficult to make because of the structure of the code.
Rather than start from scratch to build a 100% brand new version of the site under Symfony (which will take months and nothing happens on the existing live app in the meantime), I'd like to try a hybrid approach. I would carve off a \~standalone piece of my app and rebuild it in Symfony, then swap out that chunk on the live app so the Symfony version would be running alongside the rest of the (legacy) app. Lather, rinse, repeat until the whole thing is under Symfony.
The goal is to keep up development on the main app and make structural improvements along the way while transitioning the whole thing to Symfony. (And yes, I realize that in practice it won't be this smooth and sometimes the pieces of my app will dramatically overlap, causing much heartache and hassle... but for now let's pretend my app is relatively modular and can be easily broken down into standalone chunks.)
I assume this is *possible;* my question is, would it be a good idea to get my app updated into a nice modern sexy framework?
4 thoughts on “How reasonable would it be to refactor a large, existing PHP app (with no framework) into the Symfony framework and run the app “live” as it transitions piece-by-piece?”
This sounds like a sensible approach to me if you can find the “seams” at which it makes sense to break your app up.
I think the best thing to do would be to set up 2 virtual hosts in apache with rules for the new and old routes accordingly. Although I’ll be interested to see what other people suggest.
Sounds like a fun project, good luck!
Symfony have already documented one strategy on their site…
Basically you route all traffic to the new application, but create a special catch all route that handles unknown routes, and pass it to the old application, then use php buffer method to catch the output 🙂
My gut says don’t do it. Symfony is not a silver bullet that will solve your problem. I would find a feature that you want to add that has data that can be protected by a separate service app only accessible via a good thoughtful API. You can use Symfony but there plenty of simpler frameworks. Have you legacy app access the data via a client. Use this new app to learn and implement authentication, authorization, caching .. etc. Actually your business logic code should be framework agnostic. Check out the Onion or Hexagonal architecture.
I think it is better to refactor the legacy app. Work on applying some software design patterns to the existing code without changing the functionality. Then you will be able to see the seams. After that you will be able to replace legacy objects with new services.
Yes, what you’re after is the strangler pattern. It’s a very good way to accomplish what you want to do. This article gives a good overview of it