title: Symfony 2 and custom session variables from legacy application
body: <p>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.</p>
  
  <p>I can currently <code>var_dump($_SESSION)</code> in <code>app_dev.php</code> and the <code>user_id</code> key comes through from the legacy application. However, when I run the following in a controller, I don't get any session variables:</p>
  
  <pre><code>var_dump($request-&gt;getSession()-&gt;all());
  </code></pre>
  
  <p><strong>So to clarify</strong>, I currently have access to <code>$_SESSION['user_id']</code>, so the session is shared between applications successfully, but the Symfony session object and it's parameter bags do not contain the legacy keys.</p>
  
  <p>My goal:</p>
  
  <ul>
  <li>For the <code>user_id</code> key to be available in the <code>$request-&gt;getSession()</code> call</li>
  <li>For all other keys to be available here</li>
  </ul>
  
  <p>My problems:</p>
  
  <p>I have tried the <a href="http://symfony.com/doc/current/cookbook/session/php_bridge.html" rel="nofollow noreferrer">PHP Session bridge</a> 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 <a href="https://stackoverflow.com/a/28160980/736809">read</a> this is meant to be used somehow in <em>the other</em> legacy application, not in Symfony.</p>
  
  <blockquote>
    <p>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. <em>[From <a href="http://symfony.com/doc/current/components/http_foundation/session_php_bridge.html" rel="nofollow noreferrer">Integrating with legacy sessions</a>]</em></p>
  </blockquote>
  
  <p>I've also taken a look at <a href="https://github.com/theodo/TheodoEvolutionSessionBundle" rel="nofollow noreferrer">TheodoEvolutionSessionBundle</a>, but this is old, isn't actively supported or worked on and doesn't work with Symfony 3.</p>
  
  <p>I have noticed that Symfony stores it's session data under <code>$_SESSION['_sf2_attributes']</code>, so my initial thought was to do this in <code>app_dev.php</code>:</p>
  
  <pre><code>$_SESSION['_sf2_attributes']['user_id'] = $_SESSION['user_id'];
  </code></pre>
  
  <p>This is <em>clearly</em> the wrong way to do this, as I also have to call <code>session_start()</code> in there as well.</p>
  
  <p><strong>How can I migrate legacy $_SESSION data into Symfony's Session object?</strong> Is there something built-in to Symfony to help with this or a bundle available? If there isn't, <em>where</em> can I place my custom <code>$_SESSION['_sf2_attributes']</code> 'hack' in the correct place to handle the migration of all these keys?</p>