Using Symfony DIC as a stand-alone component is possible , but you will have to do a lot of things βmanuallyβ (since you are not planning on using the full Symfony Framework from the beginning). You probably won't use DIC with all this legacy.
If you want to go this route, I would prefer to first select another component (for example, HttpFoundation and HttpKernel).
As @Cerad suggested you wrap your old code in Symfony. Check out the IngewikkeldWrapperBundle bundle. You cannot use it as is, but it can give you some ideas.
There is a third way.
You can implement every new feature in a Symfony application. Then you can make both the Symfony apps and the apps coexist. At the server level (i.e. Nginx), you can proxy obsolete URLs for the legacy application and all migrated URLs to the Symfony2 application. In my case, this scenario was the best option and turned out to be workable. However, we tried to abandon the development of obsolete applications (therefore, every new feature or change should have been developed in the Symfony2 application).
Edit: this is how you could load the Symfony core in an outdated application and send an event (which is necessary for the firewall):
$kernel = new \AppKernel('dev', true); $kernel->boot(); $request = Request::createFromGlobals(); $request->attributes->set('is_legacy', true); $request->server->set('SCRIPT_FILENAME', 'app.php'); $container = $kernel->getContainer(); $container->enterScope('request'); $container->get('request_stack')->push($request); $container->set('request', $request); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $eventDispatcher = $container->get('event_dispatcher'); $eventDispatcher->dispatch('kernel.request', $event);
Jakub zalas
source share