【发布时间】:2014-07-08 10:25:18
【问题描述】:
我对通过工厂实例化的 A 类和 B 类扩展 A 类有疑问。
这里有一些示例代码:
class ClassAFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$one= $serviceLocator->get('doctrine.entitymanager.one');
$two= $serviceLocator->get('doctrine.entitymanager.two');
$three= $serviceLocator->get('Application\Service\three');
return new ClassA($one, $two, $three);
}
}
class ClassA implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
private $one;
private $two;
private $three;
public function __construct(ObjectManager $one, ObjectManager $two, Three $three)
{
$this->one= $one;
$this->two= $two;
$this->three= $three;
}
}
class ClassB extends ClassA
{
// Some usefull code
}
如何在不传递依赖关系的情况下调用 B 类,如何检索工厂完成的 A 类实例:new ClassB(); ?
【问题讨论】:
标签: php dependency-injection zend-framework2 factory