. */ namespace Doctrine\ORM; use Doctrine\ORM\Mapping\AssociationMapping; /** * Represents a virtual proxy that is used for lazy to-one associations. * * @author robo * @since 2.0 */ class VirtualProxy { private $_assoc; private $_refProp; private $_owner; /** * Initializes a new VirtualProxy instance that will proxy the specified property on * the specified owner entity. The given association is used to lazy-load the * real object on access of the proxy. * * @param $owner * @param $assoc * @param $refProp */ public function __construct($owner, AssociationMapping $assoc, \ReflectionProperty $refProp) { $this->_owner = $owner; $this->_assoc = $assoc; $this->_refProp = $refProp; } private function _load() { $realInstance = $tis->_assoc->lazyLoadFor($this->_owner); $this->_refProp->setValue($this->_owner, $realInstance); return $realInstance; } /** All the "magic" interceptors */ public function __call($method, $args) { $realInstance = $this->_load(); return call_user_func_array(array($realInstance, $method), $args); } public function __get($prop) { $realInstance = $this->_load(); return $realInstance->$prop; } public function __set($prop, $value) { $realInstance = $this->_load(); $realInstance->$prop = $value; } public function __isset($prop) { $realInstance = $this->_load(); return isset($realInstance->$prop); } public function __unset($prop) { $realInstance = $this->_load(); unset($realInstance->$prop); } }