From: Thomas K. <th...@ko...> - 2014-12-29 06:30:56
|
On Saturday, December 20, 2014 01:56:17 PM Elier Delgado wrote: > I did some tests with symfony2 and I was able to generate several CRUD > in a > few hours We've ported a legacy PHP non-MVC application to Symfony last year step by step without downtime. Our strategy was: a) Move all files in the standard Symfony folders app/,src/, web/ b) autogenerate Symfony Routes for all PHP files that were formerly entered directly: $collection = new RouteCollection(); $finder = (new Finder())->in($this->dir)->files()->name('*.php'); foreach($finder as $phpFile) { $collection->add( $this->buildNameFor($phpFile), $this->buildRouteFor($phpFile) ); } return $collection; c) Add a default controller for all legacy PHP files: class LegacyRoutesController extends Controller { private static $redirect = null; public function defaultAction($_route, $_legacyPath) { ob_start(); $ret = require $_legacyPath; $out = ob_get_contents(); ob_end_clean(); if($ret instanceof Response) return $ret; if(self::$redirect) return $this->redirect(self::$redirect); return new Response($out); } d) The old PHP files now have access to $this and thus can use Symfony services like template engine (twig), form handlers, request, response objects, database (doctrine), email (swiftmailer) e) Replace old PHP files with MVC controllers step by step ... z) (Port to Java Spring...) |