1

更新以反映讨论

我想实现一些自定义逻辑来选择正确的实体管理器。我认为这就像覆盖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]);
    }
}

我在这里想念什么?

4

1 回答 1

1

您正试图在第21行获取该类的name不存在属性:TenantRegistry

                                                           here
throw new \InvalidArgumentException(sprintf(                 ↓
    'Doctrine %s Manager named "%s" does not exist.', $this->name, $name));

更新

属性name在类中定义,AbstractManagerRegistry并且具有私有访问权限。因此,您无法直接获取此属性。请改用该getName()方法。

于 2013-04-04T05:42:46.797 回答