Porting an obsolete application to Symfony2: how to execute native php scripts in a controller?

I have an outdated application that I would like to move to Symfony2. This application is not created in MVC, it is not compatible with PSR-0, it is a very inherited application in which "/search.php" points to the file "search.php", and menus, headers and footers include different files.

If I could somehow connect this application quickly and dirty to Symfony2, and then start moving the pieces to it one at a time to the Symfony2 application architecture, which would be ideal. I really would not want to try to make a waterfall, to convey all this, and then do some massive update after 3-6 months. Can anyone recommend a way to execute a native php script that includes things like mysql queries in a Symfony2 controller or some other way to do this? I am currently browsing, possibly files in php or twig templates. Thanks!

+4
source share
1 answer

Think about it at the server level. Your web server should be able to route part of the URLs to the new website and the rest to the legacy (at least Nginx can do this). After you move on to rewriting, you just need to change the rewrite URLs and redirect the additional URLs to the new application.

Doing this in a Symfony controller should be pretty simple (I haven't tried it yet). You will need a fallback route that triggers an action similar to the following:

public function legacyAction() { // decide which file to include $legacyFile = '/path/to/legacy-app/search.php'; ob_start(); include($legacyFile); $content = ob_get_clean(); return new Response($content); } 

Perhaps this is simplified, but should demonstrate the idea.

+5
source

Source: https://habr.com/ru/post/1433629/


All Articles