簡體   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