TYPO3 CMS  TYPO3_8-7
LazyLoadingProxy.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
24 {
28  protected $dataMapper;
29 
35  private $parentObject;
36 
42  private $propertyName;
43 
49  private $fieldValue;
50 
54  public function injectDataMapper(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper)
55  {
56  $this->dataMapper = $dataMapper;
57  }
58 
67  {
68  $this->parentObject = $parentObject;
69  $this->propertyName = $propertyName;
70  $this->fieldValue = $fieldValue;
71  }
72 
78  public function _loadRealInstance()
79  {
80  // this check safeguards against a proxy being activated multiple times
81  // usually that does not happen, but if the proxy is held from outside
82  // its parent ... the result would be weird.
83  if ($this->parentObject->_getProperty($this->propertyName) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
84  $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false, false);
85  $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
86  $this->parentObject->_setProperty($this->propertyName, $propertyValue);
87  $this->parentObject->_memorizeCleanState($this->propertyName);
88  return $propertyValue;
89  }
90  return $this->parentObject->_getProperty($this->propertyName);
91  }
92 
96  public function _getTypeAndUidString()
97  {
98  $type = $this->dataMapper->getType(get_class($this->parentObject), $this->propertyName);
99  return $type . ':' . $this->fieldValue;
100  }
101 
109  public function __call($methodName, $arguments)
110  {
111  $realInstance = $this->_loadRealInstance();
112  if (!is_object($realInstance)) {
113  return null;
114  }
115  return call_user_func_array([$realInstance, $methodName], $arguments);
116  }
117 
124  public function __get($propertyName)
125  {
126  $realInstance = $this->_loadRealInstance();
127  return $realInstance->{$propertyName};
128  }
129 
136  public function __set($propertyName, $value)
137  {
138  $realInstance = $this->_loadRealInstance();
139  $realInstance->{$propertyName} = $value;
140  }
141 
148  public function __isset($propertyName)
149  {
150  $realInstance = $this->_loadRealInstance();
151  return isset($realInstance->{$propertyName});
152  }
153 
159  public function __unset($propertyName)
160  {
161  $realInstance = $this->_loadRealInstance();
162  unset($realInstance->{$propertyName});
163  }
164 
170  public function __toString()
171  {
172  $realInstance = $this->_loadRealInstance();
173  return $realInstance->__toString();
174  }
175 
181  public function current()
182  {
183  $realInstance = $this->_loadRealInstance();
184  return current($realInstance);
185  }
186 
192  public function key()
193  {
194  $realInstance = $this->_loadRealInstance();
195  return key($realInstance);
196  }
197 
201  public function next()
202  {
203  $realInstance = $this->_loadRealInstance();
204  next($realInstance);
205  }
206 
210  public function rewind()
211  {
212  $realInstance = $this->_loadRealInstance();
213  reset($realInstance);
214  }
215 
221  public function valid()
222  {
223  return $this->current() !== false;
224  }
225 }
injectDataMapper(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper)
__construct($parentObject, $propertyName, $fieldValue)