ZF2-567: AbstractFactory : createServiceWithName even if canCreateServiceWithName return false
Description
This code echos "create the wrong one" instead of "create the good one" :
<?php
class Af1 implements \Zend\ServiceManager\AbstractFactoryInterface
{
public function canCreateServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return true;
}
public function createServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
echo "create the good one";
return new stdClass();
}
}
class Af2 implements \Zend\ServiceManager\AbstractFactoryInterface
{
public function canCreateServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return false;
}
public function createServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
echo "create the wrong one";
return new stdClass();
}
}
$sm = new \Zend\ServiceManager\ServiceManager();
$sm->addAbstractFactory('Af1');
$sm->addAbstractFactory('Af2');
$sm->get('test');
?>
If I switch both "addAbstractFactory", it work fine.
Comments
Posted by Ralph Schindler (ralph) on 2012-10-08T20:12:23.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2593