当我运行时doctrine orm:validate-schema,会弹出一堆关于我的映射列是公共的警告,而不是使用getter/setter方法来包装它们.它说他们"打破懒惰装载".我可以理解如何使公共关联集合成为问题(我确实将它们设为私有并将它们包装起来),但这对于对象上的字段来说又是怎样的问题?据我所知,字段已全部加载.
请注意,Doctrine 2.4现在支持具有公共属性的entites的代理对象.
Marco Pivetta的网站解释了它的工作原理:
class Customer {
public $name;
public $surname;
}
class CustomerProxy extends Customer {
public function __construct(Customer $customer) {
unset($this->name, $this->surname);
$this->customer = $customer;
}
public function __set($name, $value) {
$this->customer->$name = $value;
}
public function __get($name) {
return $this->customer->$name;
}
// __isset, __unset, __clone, __sleep, __wakeup (or serialize/unserialize)
}
Run Code Online (Sandbox Code Playgroud)