title: Symfony2 conditional service declaration
body: <p>I'm currently trying to find a solid solution to change the dependencies of a Symfony2 service dynamically. In detail: I have a Services which uses a HTTP-Driver to communicate with an external API.</p>
  
  <pre><code>class myAwesomeService
  {
      private $httpDriver;
  
      public function __construct(
          HTTDriverInterface $httpDriver
      ) {
          $this-&gt;httpDriver = $httpDriver;
      }
  
      public function transmitData($data)
      {
          $this-&gt;httpDriver-&gt;dispatch($data);
      } 
  }
  </code></pre>
  
  <p>While running the Behat tests on the CI, I'd like to use a httpMockDriver instead of the real driver because the external API might be down, slow or even broken and I don't want to break the build.</p>
  
  <p>At the moment I'm doing something like this:</p>
  
  <pre><code>&lt;?php
  namespace MyAwesome\TestBundle\DependencyInjection;
  
  class MyAwesomeTestExtension extends Extension
  {
      /**
       * {@inheritDoc}
       */
      public function load(array $configs, ContainerBuilder $container)
      {
          $configuration = new Configuration();
          $config = $this-&gt;processConfiguration($configuration, $configs);
  
          $loader = new Loader\YamlFileLoader($container, new       
                       FileLocator(__DIR__.'/../Resources/config'));
          $environment = //get environment
          if ($environment == 'test') {
              $loader-&gt;load('services_mock.yml');         
          } else {
              $loader-&gt;load('services.yml');          
          }
      }
  }
  </code></pre>
  
  <p>This works for now, but will break for sure. So, is there a more elegant/solid way to change the HTTPDriver dynamically?</p>