繁体   English   中英

ReflectionMethod调用学说实体返回的代理

[英]ReflectionMethod Invoke on doctrine entity returns proxies

我试图用反射调用实体获取器,但是它返回一些奇怪的对象:

代理__CG __ \\ Foo \\ InvoiceBundle \\ Entity \\ Invoice

代替

Foo \\ InvoiceBundle \\ Entity \\ Invoice

这是我的代码:

class ProperProperty extends \ReflectionProperty{

    public function __construct(){
        parent::__construct();
    }

    private function getGetterName($propertyName){
        $ret = "get" . ucfirst($propertyName);
        return $ret;
    }

    public function getDoctrineValue($class, $object){
        $propertyName = $this->getName();
        $getterName = $this->getGetterName($propertyName);
        $reflectionMethod = new \ReflectionMethod($class, $getterName);
        $ret = $reflectionMethod->invoke($object);
        return $ret;
    }
}

我看到代理类在某种程度上是延迟加载的对象,无论如何都要强制加载? 感谢:D

如果有人对如何填写空代理感兴趣:

protected function loadProxy($object){
        $class = get_class($object);
        if (strpos($class, "Proxies") === false)
            return;

        $methodName = "__load";
        $reflectionMethod = new \ReflectionMethod($class, $methodName);
        $ret = $reflectionMethod->invoke($object);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM