我试图用反射调用一个实体getter,但它返回了一些奇怪的对象:
代理人__CG__\Foo\InvoiceBundle\Entity\Invoice
而不是
Foo\InvoiceBundle\实体\发票
这是我的代码:
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);
}