【发布时间】:2015-05-30 13:40:18
【问题描述】:
我已经为 EntityManager 创建了自定义装饰器,现在当我在做 doctrine->getManager() 时,我可以获得自定义管理器类,但在存储库类中我仍然有本机 EntityManager 我该如何解决这个问题。或者也许还有另一种方法可以在容器的存储库类中设置一些东西?
装饰器在 $wrapped(EntityManager) 上调用 getRepository,然后 $wrapped 在 RepositoryFactory $this == $wrapped == EntityManager 中传递 $this
我的解决方案是:
public function getRepository($className)
{
$repository = parent::getRepository($className);
if ($repository instanceof MyAbstractRepository) {
$repository->setDependency();
}
return $repository;
}
【问题讨论】:
标签: symfony doctrine-orm