00001 <?php 00055 class Object_Freezer_LazyProxy 00056 { 00060 protected $storage; 00061 00065 protected $uuid; 00066 00070 protected $thawedObject; 00071 00078 public function __construct(Object_Freezer_Storage $storage, $uuid) 00079 { 00080 $this->storage = $storage; 00081 $this->uuid = $uuid; 00082 } 00083 00089 public function getObject() 00090 { 00091 if ($this->thawedObject === NULL) { 00092 $this->thawedObject = $this->storage->fetch($this->uuid); 00093 } 00094 00095 return $this->thawedObject; 00096 } 00097 00105 public function __get($name) 00106 { 00107 $object = $this->replaceProxy(2); 00108 $attribute = new ReflectionProperty($object, $name); 00109 $attribute->setAccessible(TRUE); 00110 00111 return $attribute->getValue($object); 00112 } 00113 00121 public function __set($name, $value) 00122 { 00123 $object = $this->replaceProxy(2); 00124 $attribute = new ReflectionProperty($object, $name); 00125 $attribute->setAccessible(TRUE); 00126 00127 $attribute->setValue($object, $value); 00128 } 00129 00138 public function __call($name, $arguments) 00139 { 00140 $object = $this->replaceProxy(3); 00141 $reflector = new ReflectionMethod($object, $name); 00142 00143 return $reflector->invokeArgs($object, $arguments); 00144 } 00145 00152 protected function replaceProxy($offset) 00153 { 00154 $object = $this->getObject(); 00155 00164 $trace = debug_backtrace(); 00165 00166 if (isset($trace[$offset]['object'])) { 00167 $reflector = new ReflectionObject($trace[$offset]['object']); 00168 00169 foreach ($reflector->getProperties() as $attribute) { 00170 $attribute->setAccessible(TRUE); 00171 00172 if ($attribute->getValue($trace[$offset]['object']) === $this) { 00173 $attribute->setValue($trace[$offset]['object'], $object); 00174 break; 00175 } 00176 } 00177 } 00178 00179 return $object; 00180 } 00181 }