已更新以反映讨论
我想实现一些自定义逻辑来选择正确的实体管理器。我认为这就像覆盖doctrine.class参数一样简单,扩展Doctrine \ Bundle \ DoctrineBundle \ Registry并覆盖getManager()方法。但是,当我这样做时,我收到以下错误:
ErrorException: Warning: strtolower() expects parameter 1 to be string, object given in /Applications/MAMP/htdocs/nmevent/app/bootstrap.php.cache line 119
以下是代码:
<?php
namespace NM\Bundle\MultiTenantBundle\Doctrine;
use Doctrine\Bundle\DoctrineBundle\Registry;
class TenantRegistry extends Registry
{
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
public function getManager($name = null)
{
if (null === $name) {
$name = $this->defaultManager;
}
$managers = $this->getManagers();
if (!isset($managers[$name])) {
throw new \InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->getName(), $name));
}
return $this->getService($managers[$name]);
}
}
我在这里缺少什么?
答案 0 :(得分:1)
您正在尝试在 21 行<{1}}上获取name
课程中不存在的属性TenantRegistry
:
here
throw new \InvalidArgumentException(sprintf( ↓
'Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
<强> UPD 强>:
属性name
在AbstractManagerRegistry
类中定义,并且具有私有访问权限。所以,你无法直接获得这个属性。请改用getName()
方法。