Issues

ZF2-260: Support for classnames as parameter value in DI

Description

Currently I'm trying to configure Doctrine2 with ZF2/DI and in some cases it's necessary to specify a class name (string). Example: "defaultRepositoryClassName" parameter of Doctrine\ORM\Configuration should be something like "MyLib\MyRepository" This is (afaik) not possible with the current DIC because "MyLib\MyRepository" will be recognized as class and therefore it will we instantiated and a reference will be used during injection.

Comments


return array(
    'di' => array(
        'definition' => array(
            'class' => array(
                'Doctrine\ORM\Configuration' => array(
                    'methods' => array(
                        'setDefaultRepositoryClassName' => array(
                                'defaultRepositoryClassName' => array('type' => false, 'required' => true)
                        ),
                     ),
                ),
            ),
        ),
    ),
);

'type' => false does the magic ;)

Assuming that type => false is the correct way to inject strings instead of classnames, I found another part where this is currently not working:

Use case: There is a class with a method which expects a classname (not an instance). You want to inject multiple class names in this method

Given: definition with method "addMyParam" and a param "myClassName" => array('type'=>false). instance with 'injections' array to set the classnames.

Result: Somehow the class definition of the given class names is already known by DI. Maybe because of some RunetimeDefinition (I just started looking into DI). During resolveMethodParameters() in the "priority 1"-code the given string (classname) will be checked if the string is a known class name (which is the case) and instantiated.

Expected: Still assuming that type=>false indicates that it is a string instead of an object, it should not instntiate the class.

Bugfix: Checking if the classname is known by the DI AND checking if type !== false

Fixed in master