title: PHP - DI container in a REST client
body: <p>I am trying to build a basic REST client in PHP as a way to make myself familiar with the concept of dependency injection container. Ultimately, I would like to do something like:</p>
  
  <pre><code>$client = new RestClient();
  $client-&gt;getService('user', array('id, optional fields...'));
  </code></pre>
  
  <p>But I also want to be able to specify which object should handle the request (if I want to use fopen instead of curl, for instance).</p>
  
  <p>According to what I've read so far, a proper way to achieve this would be:</p>
  
  <pre><code>$request = new ServiceDefinition( 
      'Curl', 
      array('...') 
  ); 
  $user = new ServiceDefinition('User',  
      array(new ServiceReference('request')) 
  ); 
  $container = new ServiceContainer(array( 
      'request' =&gt; $request, 
      'user'    =&gt; $user, 
  ));
  </code></pre>
  
  <p>My question is: is there a simpler way to build the dependency between the user object and the request object ? (a basic setter injection on RestClient(), maybe ?)</p>
  
  <p>Thanks in advance.</p>