Moving a legacy application to Symfony2: How to execute native php scripts in a controller?

StackOverflow https://stackoverflow.com/questions/12374946

  •  01-07-2021
  •  | 
  •  

Question

I have a legacy application that I would like to move over to Symfony2. This application is not built in MVC, it has no PSR-0 compatibility, it is very much a legacy application in that '/search.php' points to a file 'search.php' and the menu, headers, and footers are includes different files share.

If I could somehow plug in this application quick and dirty into Symfony2 and then begin moving pieces of over to it one at a time to the Symfony2 application architecture that would be ideal. I really would not like to make some waterfall attempt to port the whole thing over and then do some massive update in 3-6 months. Can anyone recommend a way to execute a native php script that would include things like mysql queries in a Symfony2 controller or some other best way to do this? I am currently looking at perhaps including the files in php or twig templates. Thanks!

Was it helpful?

Solution

Consider doing it on a server level. Your web server should be able to route part of the URLs to the new website and rest of them to legacy (at least Nginx is able to do it). Once you move forward with the rewrite you'll just need to alter URL rewrites and route additional URLs to the new application.

Doing this in Symfony controller should be fairly easy as well (I haven't tried this though). You'll need a fallback route which would call 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);
}

It's probably to simplistic but should demonstrate the idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top