I recently added support to @Value annotation to the ServiceContainerAnnotationsLoader. See my previous post for detailed information about this loader for Symfony Dependency Injection component.

Inspired by Spring Framework 3.0 new equivalent annotation, it allows to inject parameter values defined in your service container with a simple annotation in your services. Check the updated code on my Bitbucket.

If you use @Value without description, the parameter identifier will be automatically determined. You can also explicitly define the parameter identifier: @Value %mail.transport%.

parameters:
    foo: bar
    mailer.username: foo
    mailer.password: bar
/** 
 * @Service 
 */ 
class Default_Service_TestService 
{ 
    /** 
     * @Value
     */ 
    protected $_foo; 
  
    public function setFoo($foo) 
    { 
        $this->_foo = $foo; 
        return $this; 
    }

    protected $_username;

    /*
     * @Value %mailer.username%
     */
    public function setUsername($username)
    {
        $this->_username = $username;
        return $this;
    }

    // ....
}