class MyController
{
public function __construct(Config $config) {}
}
according to the documentation
An IoC container service name as string: This is only possible if the required type is a class or interface. For other types (scalars, iterable, callable, etc) or typeless parameters, the string value is passed as is.
(see: https://docs.zendframework.com/zend-di/config/#parameters)
it should work correctly, so we should have generated factory for MyController:
class MyControllerFactory
{
public function __invoke(ContainerInterface $container)
{
return new MyController($container->get('my-service.config'));
}
}
but unfortunately parameter resolver try to check the type.
If we add:
then the factory for MyController is as expected but unfortunately also factory for my-service.config is created and replaced with the one configured in service-manager.
Issue description
Please consider the following configuration:
where
MyController
is as follows:according to the documentation
it should work correctly, so we should have generated factory for
MyController
:but unfortunately parameter resolver try to check the type. If we add:
then the factory for
MyController
is as expected but unfortunately also factory formy-service.config
is created and replaced with the one configured inservice-manager
.The correct result we can get if we have:
but this is not ideal (new instances in the static configuration).
Solution
We don't need to check type if typehint is class/interface and configuration is string.
master
branch, and submit against that branch.CHANGELOG.md
entry for the fix.