TYPO3 CMS  TYPO3_6-2
LazyLoadingProxy.php
Go to the documentation of this file.
1 <?php
3 
21 
26  protected $dataMapper;
27 
33  private $parentObject;
34 
40  private $propertyName;
41 
47  private $fieldValue;
48 
57  $this->parentObject = $parentObject;
58  $this->propertyName = $propertyName;
59  $this->fieldValue = $fieldValue;
60  }
61 
67  public function _loadRealInstance() {
68  // this check safeguards against a proxy being activated multiple times
69  // usually that does not happen, but if the proxy is held from outside
70  // it's parent... the result would be weird.
71  if ($this->parentObject->_getProperty($this->propertyName) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
72  $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE, FALSE);
73  $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
74  $this->parentObject->_setProperty($this->propertyName, $propertyValue);
75  $this->parentObject->_memorizeCleanState($this->propertyName);
76  return $propertyValue;
77  } else {
78  return $this->parentObject->_getProperty($this->propertyName);
79  }
80  }
81 
89  public function __call($methodName, $arguments) {
90  $realInstance = $this->_loadRealInstance();
91  if (!is_object($realInstance)) {
92  return NULL;
93  }
94  return call_user_func_array(array($realInstance, $methodName), $arguments);
95  }
96 
103  public function __get($propertyName) {
104  $realInstance = $this->_loadRealInstance();
105  return $realInstance->{$propertyName};
106  }
107 
115  public function __set($propertyName, $value) {
116  $realInstance = $this->_loadRealInstance();
117  $realInstance->{$propertyName} = $value;
118  }
119 
126  public function __isset($propertyName) {
127  $realInstance = $this->_loadRealInstance();
128  return isset($realInstance->{$propertyName});
129  }
130 
137  public function __unset($propertyName) {
138  $realInstance = $this->_loadRealInstance();
139  unset($realInstance->{$propertyName});
140  }
141 
147  public function __toString() {
148  $realInstance = $this->_loadRealInstance();
149  return $realInstance->__toString();
150  }
151 
157  public function current() {
158  $realInstance = $this->_loadRealInstance();
159  return current($realInstance);
160  }
161 
167  public function key() {
168  $realInstance = $this->_loadRealInstance();
169  return key($realInstance);
170  }
171 
177  public function next() {
178  $realInstance = $this->_loadRealInstance();
179  next($realInstance);
180  }
181 
187  public function rewind() {
188  $realInstance = $this->_loadRealInstance();
189  reset($realInstance);
190  }
191 
197  public function valid() {
198  return $this->current() !== FALSE;
199  }
200 }
__construct($parentObject, $propertyName, $fieldValue)