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;
    }

    // ....
}

Now we can use annotations to load our services definitions into the Symfony Dependency Injection container.

For the second part of this series on Dependency Injection, we are going to see an elegant way to integrate the Symfony service container with your Zend Framework application.

Read the rest of this entry »

Having worked a lot with Spring Framework for Java EE projects, I was looking for an Inversion of Control container for managing Dependency Injection in PHP in my Zend Framework applications instead of factories. I closely followed Fabien Potencier’s (Symfony’s project lead) series on Dependency Injection in spring (season) 2009 and I recently took the time to begin testing the Dependency Injection container from Symfony Components. Quite satisfied with it I decided to integrate it with Zend Framework and to add the possibility to use docblock annotations to describe services with a new loader for the component.

Read the rest of this entry »