‪TYPO3CMS  10.4
LazyLoadingProxy.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
29 {
33  protected ‪$dataMapper;
34 
40  private ‪$parentObject;
41 
47  private ‪$propertyName;
48 
54  private ‪$fieldValue;
55 
59  protected ‪$objectManager;
60 
65  {
66  $this->objectManager = ‪$objectManager;
67  }
68 
78  {
79  $this->parentObject = ‪$parentObject;
80  $this->propertyName = ‪$propertyName;
81  $this->fieldValue = ‪$fieldValue;
82  $this->dataMapper = ‪$dataMapper;
83  }
84 
88  public function ‪initializeObject()
89  {
90  if (!$this->dataMapper) {
91  $this->dataMapper = $this->objectManager->get(DataMapper::class);
92  }
93  }
94 
100  public function ‪_loadRealInstance()
101  {
102  // this check safeguards against a proxy being activated multiple times
103  // usually that does not happen, but if the proxy is held from outside
104  // its parent ... the result would be weird.
105  if ($this->parentObject instanceof AbstractDomainObject
106  && $this->parentObject->_getProperty($this->propertyName) instanceof LazyLoadingProxy
107  && $this->dataMapper
108  ) {
109  $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false);
110  $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
111  $this->parentObject->_setProperty($this->propertyName, $propertyValue);
112  $this->parentObject->_memorizeCleanState($this->propertyName);
113  return $propertyValue;
114  }
115  return $this->parentObject->_getProperty($this->propertyName);
116  }
117 
121  public function ‪_getTypeAndUidString()
122  {
123  $type = $this->dataMapper->getType(get_class($this->parentObject), $this->propertyName);
124  return $type . ':' . ‪$this->fieldValue;
125  }
126 
130  public function ‪getUid(): int
131  {
132  return (int)‪$this->fieldValue;
133  }
134 
142  public function ‪__call($methodName, $arguments)
143  {
144  $realInstance = $this->‪_loadRealInstance();
145  if (!is_object($realInstance)) {
146  return null;
147  }
149  $callable = [$realInstance, $methodName];
150  return call_user_func_array($callable, $arguments);
151  }
152 
159  public function ‪__get(‪$propertyName)
160  {
161  $realInstance = $this->‪_loadRealInstance();
162  return $realInstance->{‪$propertyName};
163  }
164 
171  public function __set($propertyName, $value)
172  {
173  $realInstance = $this->_loadRealInstance();
174  $realInstance->{$propertyName} = $value;
175  }
176 
183  public function __isset($propertyName)
184  {
185  $realInstance = $this->_loadRealInstance();
186  return isset($realInstance->{$propertyName});
187  }
188 
194  public function __unset($propertyName)
195  {
196  $realInstance = $this->_loadRealInstance();
197  unset($realInstance->{$propertyName});
198  }
199 
205  public function __toString()
206  {
207  $realInstance = $this->_loadRealInstance();
208  return $realInstance->__toString();
209  }
210 
216  public function current()
217  {
218  // todo: make sure current() can be performed on $realInstance
219  $realInstance = $this->_loadRealInstance();
220  return current($realInstance);
221  }
222 
228  public function key()
229  {
230  // todo: make sure key() can be performed on $realInstance
231  $realInstance = $this->_loadRealInstance();
232  return key($realInstance);
233  }
234 
238  public function next()
239  {
240  // todo: make sure next() can be performed on $realInstance
241  $realInstance = $this->_loadRealInstance();
242  next($realInstance);
243  }
244 
248  public function rewind()
249  {
250  // todo: make sure reset() can be performed on $realInstance
251  $realInstance = $this->_loadRealInstance();
252  reset($realInstance);
253  }
254 
260  public function valid()
261  {
262  return $this->current() !== false;
263  }
264 }
‪TYPO3\CMS\Extbase\Persistence\Generic\LoadingStrategyInterface
Definition: LoadingStrategyInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\next
‪next()
Definition: LazyLoadingProxy.php:233
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\key
‪int key()
Definition: LazyLoadingProxy.php:223
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__get
‪mixed __get($propertyName)
Definition: LazyLoadingProxy.php:154
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$dataMapper
‪DataMapper null $dataMapper
Definition: LazyLoadingProxy.php:32
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__call
‪mixed __call($methodName, $arguments)
Definition: LazyLoadingProxy.php:137
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__toString
‪string __toString()
Definition: LazyLoadingProxy.php:200
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$parentObject
‪DomainObjectInterface $parentObject
Definition: LazyLoadingProxy.php:38
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
Definition: DataMapper.php:52
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\injectObjectManager
‪injectObjectManager(ObjectManagerInterface $objectManager)
Definition: LazyLoadingProxy.php:59
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\valid
‪bool valid()
Definition: LazyLoadingProxy.php:255
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__isset
‪bool __isset($propertyName)
Definition: LazyLoadingProxy.php:178
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$objectManager
‪ObjectManagerInterface $objectManager
Definition: LazyLoadingProxy.php:54
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\_loadRealInstance
‪object _loadRealInstance()
Definition: LazyLoadingProxy.php:95
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\current
‪mixed current()
Definition: LazyLoadingProxy.php:211
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
Definition: DomainObjectInterface.php:29
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject
Definition: AbstractDomainObject.php:31
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$propertyName
‪string $propertyName
Definition: LazyLoadingProxy.php:44
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\_getTypeAndUidString
‪string _getTypeAndUidString()
Definition: LazyLoadingProxy.php:116
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\rewind
‪rewind()
Definition: LazyLoadingProxy.php:243
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:16
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__construct
‪__construct($parentObject, $propertyName, $fieldValue, ?DataMapper $dataMapper=null)
Definition: LazyLoadingProxy.php:72
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:29
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__unset
‪__unset($propertyName)
Definition: LazyLoadingProxy.php:189
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\_getProperty
‪mixed _getProperty(string $propertyName)
Definition: AbstractDomainObject.php:122
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\initializeObject
‪initializeObject()
Definition: LazyLoadingProxy.php:83
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\getUid
‪int getUid()
Definition: LazyLoadingProxy.php:125
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$fieldValue
‪mixed $fieldValue
Definition: LazyLoadingProxy.php:50
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__set
‪__set($propertyName, $value)
Definition: LazyLoadingProxy.php:166