I'm in the process of setting up the ability to migrate from a Legacy codebase to a Symfony one, and I'm trying to share legacy session variables between the two applications.
I can currently var_dump($_SESSION) in app_dev.php and the user_id key comes through from the legacy application. However, when I run the following in a controller, I don't get any session variables:
var_dump($request->getSession()->all());
So to clarify, I currently have access to $_SESSION['user_id'], so the session is shared between applications successfully, but the Symfony session object and it's parameter bags do not contain the legacy keys.
My goal:
- For the
user_idkey to be available in the$request->getSession()call - For all other keys to be available here
My problems:
I have tried the PHP Session bridge but I don't think this is supposed to do what I want it to. Not only does adding the bridge parameter not do anything in my Symfony application, but from what I've read this is meant to be used somehow in the other legacy application, not in Symfony.
Symfony sessions store data like attributes in special 'Bags' which use a key in the $_SESSION superglobal. This means that a Symfony session cannot access arbitrary keys in $_SESSION that may be set by the legacy application, although all the $_SESSION contents will be saved when the session is saved. [From Integrating with legacy sessions]
I've also taken a look at TheodoEvolutionSessionBundle, but this is old, isn't actively supported or worked on and doesn't work with Symfony 3.
I have noticed that Symfony stores it's session data under $_SESSION['_sf2_attributes'], so my initial thought was to do this in app_dev.php:
$_SESSION['_sf2_attributes']['user_id'] = $_SESSION['user_id'];
This is clearly the wrong way to do this, as I also have to call session_start() in there as well.
How can I migrate legacy $_SESSION data into Symfony's Session object? Is there something built-in to Symfony to help with this or a bundle available? If there isn't, where can I place my custom $_SESSION['_sf2_attributes'] 'hack' in the correct place to handle the migration of all these keys?