title: Symfony2 - How to inject an optional parameter
body: <p>Let's say I have a forum service. This service needs an URL to the forum API. What I want is that URL to be either internal or external. </p>
  
  <p>If <strong><em>internal</em></strong>, it would be a <strong>route</strong>, configured in routing.yml and returned by the router service.</p>
  
  <p>If <strong><em>external</em></strong>, it would be a <strong>parameter</strong>, configured in parameters.yml.</p>
  
  <p>The approach I've thought of is: </p>
  
  <p><em>Look for the variable forum_url in parameters.yml. If it doesn't exist, try to obtain that route. Else, throw Exception.</em> </p>
  
  <pre><code>services:
      forums:
          class: Acme\ForumsBundle\ForumService
          arguments: ["@doctrine.orm.entity_manager","@router", "%forum_url%"]
  </code></pre>
  
  <p>The problem with this implementation is that, if the variable is not defined, it throws an exception so what I would need is <strong>to define it as an optional parameter</strong> (like you can do with services (<strong>"@?service"</strong>). </p>
  
  <p>What would be EVEN COOLER would be to be able to define something like:</p>
  
  <pre><code>"%forum_url% ? %forum_url% : @router"
  </code></pre>
  
  <p>Any ideas on how to achieve any of this?</p>
  
  <p>PS: If there is another "better practice" approach, I'm open to inputs.</p>