‪TYPO3CMS  9.5
PersistenceManager.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 
19 
24 {
28  protected ‪$newObjects = [];
29 
33  protected ‪$changedObjects;
34 
38  protected ‪$addedObjects;
39 
43  protected ‪$removedObjects;
44 
48  protected ‪$queryFactory;
49 
53  protected ‪$backend;
54 
58  protected ‪$persistenceSession;
59 
65  {
66  $this->queryFactory = ‪$queryFactory;
67  }
68 
73  public function ‪injectBackend(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\‪BackendInterface ‪$backend)
74  {
75  $this->backend = ‪$backend;
76  }
77 
82  public function ‪injectPersistenceSession(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\‪Session ‪$persistenceSession)
83  {
84  $this->persistenceSession = ‪$persistenceSession;
85  }
86 
91  public function ‪__construct()
92  {
93  $this->addedObjects = new ‪ObjectStorage();
94  $this->removedObjects = new ‪ObjectStorage();
95  $this->changedObjects = new ‪ObjectStorage();
96  }
97 
104  public function ‪registerRepositoryClassName($className)
105  {
106  }
107 
114  public function ‪getObjectCountByQuery(‪QueryInterface $query)
115  {
116  return $this->backend->getObjectCountByQuery($query);
117  }
118 
125  public function ‪getObjectDataByQuery(‪QueryInterface $query)
126  {
127  return $this->backend->getObjectDataByQuery($query);
128  }
129 
141  public function ‪getIdentifierByObject($object)
142  {
143  return $this->backend->getIdentifierByObject($object);
144  }
145 
155  public function ‪getObjectByIdentifier($identifier, $objectType = null, $useLazyLoading = false)
156  {
157  if (isset($this->newObjects[$identifier])) {
158  return $this->newObjects[$identifier];
159  }
160  if ($this->persistenceSession->hasIdentifier($identifier, $objectType)) {
161  return $this->persistenceSession->getObjectByIdentifier($identifier, $objectType);
162  }
163  return $this->backend->getObjectByIdentifier($identifier, $objectType);
164  }
165 
170  public function ‪persistAll()
171  {
172  // hand in only aggregate roots, leaving handling of subobjects to
173  // the underlying storage layer
174  // reconstituted entities must be fetched from the session and checked
175  // for changes by the underlying backend as well!
176  $this->backend->setAggregateRootObjects($this->addedObjects);
177  $this->backend->setChangedEntities($this->changedObjects);
178  $this->backend->setDeletedEntities($this->removedObjects);
179  $this->backend->commit();
180 
181  $this->addedObjects = new ‪ObjectStorage();
182  $this->removedObjects = new ‪ObjectStorage();
183  $this->changedObjects = new ‪ObjectStorage();
184  }
185 
193  public function ‪createQueryForType($type)
194  {
195  return $this->queryFactory->create($type);
196  }
197 
203  public function ‪add($object)
204  {
205  $this->addedObjects->attach($object);
206  $this->removedObjects->detach($object);
207  }
208 
214  public function remove($object)
215  {
216  if ($this->addedObjects->contains($object)) {
217  $this->addedObjects->detach($object);
218  } else {
219  $this->removedObjects->attach($object);
220  }
221  }
222 
229  public function ‪update($object)
230  {
231  if ($this->‪isNewObject($object)) {
232  throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The object of type "' . get_class($object) . '" given to update must be persisted already, but is new.', 1249479819);
233  }
234  $this->changedObjects->attach($object);
235  }
236 
243  public function ‪injectSettings(array $settings)
244  {
245  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__, 1476108078);
246  }
247 
252  public function ‪initializeObject()
253  {
254  $this->backend->setPersistenceManager($this);
255  }
256 
266  public function ‪clearState()
267  {
268  $this->newObjects = [];
269  $this->addedObjects = new ‪ObjectStorage();
270  $this->removedObjects = new ‪ObjectStorage();
271  $this->changedObjects = new ‪ObjectStorage();
272  $this->persistenceSession->destroy();
273  }
274 
281  public function ‪isNewObject($object)
282  {
283  return $this->persistenceSession->hasObject($object) === false;
284  }
285 
298  public function ‪registerNewObject($object)
299  {
300  $identifier = $this->‪getIdentifierByObject($object);
301  $this->newObjects[$identifier] = $object;
302  }
303 
310  public function ‪convertObjectToIdentityArray($object)
311  {
312  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__, 1476108103);
313  }
314 
323  public function ‪convertObjectsToIdentityArrays(array $array)
324  {
325  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__, 1476108111);
326  }
327 
335  public function ‪tearDown()
336  {
337  if (method_exists($this->backend, 'tearDown')) {
338  $this->backend->tearDown();
339  }
340  }
341 }
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\initializeObject
‪initializeObject()
Definition: PersistenceManager.php:245
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectDataByQuery
‪array getObjectDataByQuery(QueryInterface $query)
Definition: PersistenceManager.php:118
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\registerRepositoryClassName
‪registerRepositoryClassName($className)
Definition: PersistenceManager.php:97
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectCountByQuery
‪int getObjectCountByQuery(QueryInterface $query)
Definition: PersistenceManager.php:107
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\injectSettings
‪injectSettings(array $settings)
Definition: PersistenceManager.php:236
‪TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
Definition: PersistenceManagerInterface.php:21
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$changedObjects
‪ObjectStorage $changedObjects
Definition: PersistenceManager.php:31
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\registerNewObject
‪registerNewObject($object)
Definition: PersistenceManager.php:291
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\clearState
‪clearState()
Definition: PersistenceManager.php:259
‪TYPO3
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$queryFactory
‪TYPO3 CMS Extbase Persistence Generic QueryFactoryInterface $queryFactory
Definition: PersistenceManager.php:43
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\isNewObject
‪bool isNewObject($object)
Definition: PersistenceManager.php:274
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\createQueryForType
‪QueryInterface createQueryForType($type)
Definition: PersistenceManager.php:186
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$persistenceSession
‪TYPO3 CMS Extbase Persistence Generic Session $persistenceSession
Definition: PersistenceManager.php:51
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\__construct
‪__construct()
Definition: PersistenceManager.php:84
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectByIdentifier
‪object getObjectByIdentifier($identifier, $objectType=null, $useLazyLoading=false)
Definition: PersistenceManager.php:148
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$addedObjects
‪ObjectStorage $addedObjects
Definition: PersistenceManager.php:35
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\convertObjectsToIdentityArrays
‪convertObjectsToIdentityArrays(array $array)
Definition: PersistenceManager.php:316
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\update
‪update($object)
Definition: PersistenceManager.php:222
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\injectPersistenceSession
‪injectPersistenceSession(\TYPO3\CMS\Extbase\Persistence\Generic\Session $persistenceSession)
Definition: PersistenceManager.php:75
‪TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
Definition: BackendInterface.php:21
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface
Definition: QueryFactoryInterface.php:21
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:24
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:24
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$backend
‪TYPO3 CMS Extbase Persistence Generic BackendInterface $backend
Definition: PersistenceManager.php:47
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:2
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\persistAll
‪persistAll()
Definition: PersistenceManager.php:163
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\tearDown
‪tearDown()
Definition: PersistenceManager.php:328
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$removedObjects
‪ObjectStorage $removedObjects
Definition: PersistenceManager.php:39
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\injectQueryFactory
‪injectQueryFactory(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface $queryFactory)
Definition: PersistenceManager.php:57
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\injectBackend
‪injectBackend(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface $backend)
Definition: PersistenceManager.php:66
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\convertObjectToIdentityArray
‪convertObjectToIdentityArray($object)
Definition: PersistenceManager.php:303
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$newObjects
‪array $newObjects
Definition: PersistenceManager.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getIdentifierByObject
‪mixed getIdentifierByObject($object)
Definition: PersistenceManager.php:134
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\add
‪add($object)
Definition: PersistenceManager.php:196