title: Inject a parameter into an entity in symfony2
body: <p>I feel silly asking this question but I can't find a clear answer anywhere.</p>
  
  <p>I have a <code>token</code> entity which has, among other things, a <code>creation_time</code>.</p>
  
  <p>I have a parameter in <code>parameters.yml</code> called <code>token_lifespan</code>.</p>
  
  <p>For a token, if <code>creation_time &lt; (time() - token_lifespan)</code> then it has expired.</p>
  
  <p>The problem is I can't find a nice way to pass the <code>token_lifespan</code> parameter to the entity. I know I could do something like:</p>
  
  <pre><code>$token-&gt;hasExpired($this-&gt;getParameter('token_lifespan'))
  </code></pre>
  
  <p>But that feels really icky. I've been looking at making a service, and dependency injection, as a way to pass the token lifespan to the token when it is created, but I can't work out what I'm doing.</p>
  
  <p>I'm making my tokens with <code>$token = new MyToken();</code> and I'm getting my tokens from doctrine like so:</p>
  
  <pre><code>$this-&gt;getDoctrine()
      -&gt;getRepository('MyBundle:MyToken')
      -&gt;find($token_id);
  </code></pre>
  
  <p>Do I need to make my repository a service? Something like:</p>
  
  <pre><code>mytoken_repository:
      class:  MyBundle\Entity\MyToken
      factory_service: 'doctrine.orm.default_entity_manager'
      factory_method:  'getRepository'
      calls:
           - [setLifespan, ['%token_lifespan%']]
  </code></pre>
  
  <p>And what exactly does this mean? Do I still create tokens the same way, with <code>new MyToken()</code>? and just make a <code>setLifespan</code> method in the <code>MyToken</code> class to store the lifespan?</p>
  
  <p>Finally, can I still get tokens back from Doctrine with <code>$this-&gt;getDoctrine()...</code>? and what if I need to use the <code>token_lifespan</code> parameter in my repository class?</p>
  
  <p>Sorry there's about a million questions in there. I feel like the dependency injection part of the Symfony docs assumes I know a lot more about the framework than I currently do.</p>