title: symfony 1.4 - inject current logged in user into Doctrine model
body: <p>I would like to inject, with full testability, the id of the current logged in user into a creator_id field of a Doctrine_Record class, without using the sfContext singleton. I found a couple of Doctrine behaviours like <a href="http://www.symfony-project.org/plugins/sfDoctrineActAsSignablePlugin" rel="nofollow">http://www.symfony-project.org/plugins/sfDoctrineActAsSignablePlugin</a>, but they access the sfContext singleton in a listener or (in another example I found) in the save method of a subclass of Doctrine_Record.
  I want to find a single entry point in the symfony controller, where I can inject the current logged in user and keep it till the end of the request.
  How do I do?
  Hope I have been clear enough.</p>
  
  <p>EDIT:
  As @jeremy suggested, I made a custom filter:</p>
  
  <pre><code>class userFilter extends sfFilter
  {
    public function execute($filterChain)
    {
      $user = $this-&gt;getContext()-&gt;getUser();
      if ($user-&gt;isAuthenticated()) {
        $guard = $user-&gt;getGuardUser();
        Doctrine_Manager::getInstance()-&gt;setAttribute('logged_in_user', $guard-&gt;getId());
      }
  
      // Execute next filter
      $filterChain-&gt;execute();
    }
  }
  </code></pre>
  
  <p>So now my tests and my tasks are sfContext free, I just have to set the proper user Id at some point before starting the interactions with the db:</p>
  
  <pre><code>Doctrine_Manager::getInstance()-&gt;setAttribute('logged_in_user', sfConfig::get('default_user'));
  </code></pre>