‪TYPO3CMS  9.5
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 
21 
28 {
32  protected ‪$dataMapper;
33 
39  private ‪$parentObject;
40 
46  private ‪$propertyName;
47 
53  private ‪$fieldValue;
54 
58  protected ‪$objectManager;
59 
64  {
65  $this->objectManager = ‪$objectManager;
66  }
67 
77  {
78  $this->parentObject = ‪$parentObject;
79  $this->propertyName = ‪$propertyName;
80  $this->fieldValue = ‪$fieldValue;
81  $this->dataMapper = ‪$dataMapper;
82  }
83 
87  public function ‪initializeObject()
88  {
89  if (!$this->dataMapper) {
90  $this->dataMapper = $this->objectManager->get(DataMapper::class);
91  }
92  }
93 
99  public function ‪_loadRealInstance()
100  {
101  // this check safeguards against a proxy being activated multiple times
102  // usually that does not happen, but if the proxy is held from outside
103  // its parent ... the result would be weird.
104  if ($this->parentObject instanceof AbstractDomainObject
105  && $this->parentObject->_getProperty($this->propertyName) instanceof LazyLoadingProxy
106  && $this->dataMapper
107  ) {
108  $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false);
109  $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
110  $this->parentObject->_setProperty($this->propertyName, $propertyValue);
111  $this->parentObject->_memorizeCleanState($this->propertyName);
112  return $propertyValue;
113  }
114  return $this->parentObject->_getProperty($this->propertyName);
115  }
116 
120  public function ‪_getTypeAndUidString()
121  {
122  $type = $this->dataMapper->getType(get_class($this->parentObject), $this->propertyName);
123  return $type . ':' . ‪$this->fieldValue;
124  }
125 
133  public function ‪__call($methodName, $arguments)
134  {
135  $realInstance = $this->‪_loadRealInstance();
136  if (!is_object($realInstance)) {
137  return null;
138  }
139  return call_user_func_array([$realInstance, $methodName], $arguments);
140  }
141 
148  public function ‪__get(‪$propertyName)
149  {
150  $realInstance = $this->‪_loadRealInstance();
151  return $realInstance->{‪$propertyName};
152  }
153 
160  public function __set($propertyName, $value)
161  {
162  $realInstance = $this->_loadRealInstance();
163  $realInstance->{$propertyName} = $value;
164  }
165 
172  public function __isset($propertyName)
173  {
174  $realInstance = $this->_loadRealInstance();
175  return isset($realInstance->{$propertyName});
176  }
177 
183  public function __unset($propertyName)
184  {
185  $realInstance = $this->_loadRealInstance();
186  unset($realInstance->{$propertyName});
187  }
188 
194  public function __toString()
195  {
196  $realInstance = $this->_loadRealInstance();
197  return $realInstance->__toString();
198  }
199 
205  public function current()
206  {
207  $realInstance = $this->_loadRealInstance();
208  return current($realInstance);
209  }
210 
216  public function key()
217  {
218  $realInstance = $this->_loadRealInstance();
219  return key($realInstance);
220  }
221 
225  public function next()
226  {
227  $realInstance = $this->_loadRealInstance();
228  next($realInstance);
229  }
230 
234  public function rewind()
235  {
236  $realInstance = $this->_loadRealInstance();
237  reset($realInstance);
238  }
239 
245  public function valid()
246  {
247  return $this->current() !== false;
248  }
249 }
‪TYPO3\CMS\Extbase\Persistence\Generic\LoadingStrategyInterface
Definition: LoadingStrategyInterface.php:21
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\next
‪next()
Definition: LazyLoadingProxy.php:220
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\key
‪int key()
Definition: LazyLoadingProxy.php:211
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__get
‪mixed __get($propertyName)
Definition: LazyLoadingProxy.php:143
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__call
‪mixed __call($methodName, $arguments)
Definition: LazyLoadingProxy.php:128
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__toString
‪string __toString()
Definition: LazyLoadingProxy.php:189
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$parentObject
‪DomainObjectInterface $parentObject
Definition: LazyLoadingProxy.php:37
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
Definition: DataMapper.php:32
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\injectObjectManager
‪injectObjectManager(ObjectManagerInterface $objectManager)
Definition: LazyLoadingProxy.php:58
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\valid
‪bool valid()
Definition: LazyLoadingProxy.php:240
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__isset
‪bool __isset($propertyName)
Definition: LazyLoadingProxy.php:167
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$objectManager
‪ObjectManagerInterface $objectManager
Definition: LazyLoadingProxy.php:53
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:23
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\_loadRealInstance
‪object _loadRealInstance()
Definition: LazyLoadingProxy.php:94
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\current
‪mixed current()
Definition: LazyLoadingProxy.php:200
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
Definition: DomainObjectInterface.php:26
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject
Definition: AbstractDomainObject.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$propertyName
‪string $propertyName
Definition: LazyLoadingProxy.php:43
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\_getTypeAndUidString
‪string _getTypeAndUidString()
Definition: LazyLoadingProxy.php:115
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\_getProperty
‪mixed _getProperty($propertyName)
Definition: AbstractDomainObject.php:119
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\rewind
‪rewind()
Definition: LazyLoadingProxy.php:229
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:2
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__construct
‪__construct($parentObject, $propertyName, $fieldValue, ?DataMapper $dataMapper=null)
Definition: LazyLoadingProxy.php:71
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__unset
‪__unset($propertyName)
Definition: LazyLoadingProxy.php:178
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\initializeObject
‪initializeObject()
Definition: LazyLoadingProxy.php:82
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$dataMapper
‪DataMapper $dataMapper
Definition: LazyLoadingProxy.php:31
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\$fieldValue
‪mixed $fieldValue
Definition: LazyLoadingProxy.php:49
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy\__set
‪__set($propertyName, $value)
Definition: LazyLoadingProxy.php:155