‪TYPO3CMS  10.4
PersistenceManager.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 
24 
29 {
33  protected ‪$newObjects = [];
34 
38  protected ‪$changedObjects;
39 
43  protected ‪$addedObjects;
44 
48  protected ‪$removedObjects;
49 
53  protected ‪$queryFactory;
54 
58  protected ‪$backend;
59 
63  protected ‪$persistenceSession;
64 
72  public function ‪__construct(
76  ) {
77  $this->queryFactory = ‪$queryFactory;
78  $this->backend = ‪$backend;
79  $this->persistenceSession = ‪$persistenceSession;
80 
81  $this->addedObjects = new ‪ObjectStorage();
82  $this->removedObjects = new ‪ObjectStorage();
83  $this->changedObjects = new ‪ObjectStorage();
84  }
85 
92  public function ‪registerRepositoryClassName($className)
93  {
94  }
95 
102  public function ‪getObjectCountByQuery(‪QueryInterface $query)
103  {
104  return $this->backend->getObjectCountByQuery($query);
105  }
106 
113  public function ‪getObjectDataByQuery(‪QueryInterface $query)
114  {
115  return $this->backend->getObjectDataByQuery($query);
116  }
117 
129  public function ‪getIdentifierByObject($object)
130  {
131  return $this->backend->getIdentifierByObject($object);
132  }
133 
143  public function ‪getObjectByIdentifier($identifier, $objectType = null, $useLazyLoading = false)
144  {
145  if (isset($this->newObjects[$identifier])) {
146  return $this->newObjects[$identifier];
147  }
148  if ($this->persistenceSession->hasIdentifier($identifier, $objectType)) {
149  return $this->persistenceSession->getObjectByIdentifier($identifier, $objectType);
150  }
151  return $this->backend->getObjectByIdentifier($identifier, $objectType);
152  }
153 
158  public function ‪persistAll()
159  {
160  // hand in only aggregate roots, leaving handling of subobjects to
161  // the underlying storage layer
162  // reconstituted entities must be fetched from the session and checked
163  // for changes by the underlying backend as well!
164  $this->backend->setAggregateRootObjects($this->addedObjects);
165  $this->backend->setChangedEntities($this->changedObjects);
166  $this->backend->setDeletedEntities($this->removedObjects);
167  $this->backend->commit();
168 
169  $this->addedObjects = new ‪ObjectStorage();
170  $this->removedObjects = new ‪ObjectStorage();
171  $this->changedObjects = new ‪ObjectStorage();
172  }
173 
181  public function ‪createQueryForType($type)
182  {
183  return $this->queryFactory->create($type);
184  }
185 
191  public function ‪add($object)
192  {
193  $this->addedObjects->attach($object);
194  $this->removedObjects->detach($object);
195  }
196 
202  public function remove($object)
203  {
204  if ($this->addedObjects->contains($object)) {
205  $this->addedObjects->detach($object);
206  } else {
207  $this->removedObjects->attach($object);
208  }
209  }
210 
217  public function ‪update($object)
218  {
219  if ($this->‪isNewObject($object)) {
220  throw new ‪UnknownObjectException('The object of type "' . get_class($object) . '" given to update must be persisted already, but is new.', 1249479819);
221  }
222  $this->changedObjects->attach($object);
223  }
224 
231  public function ‪injectSettings(array $settings)
232  {
233  throw new ‪NotImplementedException(__METHOD__, 1476108078);
234  }
235 
240  public function ‪initializeObject()
241  {
242  $this->backend->setPersistenceManager($this);
243  }
244 
254  public function ‪clearState()
255  {
256  $this->newObjects = [];
257  $this->addedObjects = new ‪ObjectStorage();
258  $this->removedObjects = new ‪ObjectStorage();
259  $this->changedObjects = new ‪ObjectStorage();
260  $this->persistenceSession->destroy();
261  }
262 
269  public function ‪isNewObject($object)
270  {
271  return $this->persistenceSession->hasObject($object) === false;
272  }
273 
286  public function ‪registerNewObject($object)
287  {
288  $identifier = $this->‪getIdentifierByObject($object);
289  $this->newObjects[$identifier] = $object;
290  }
291 
298  public function ‪convertObjectToIdentityArray($object)
299  {
300  throw new ‪NotImplementedException(__METHOD__, 1476108103);
301  }
302 
311  public function ‪convertObjectsToIdentityArrays(array $array)
312  {
313  throw new ‪NotImplementedException(__METHOD__, 1476108111);
314  }
315 
323  public function ‪tearDown(): void
324  {
325  if (method_exists($this->backend, 'tearDown')) {
326  $this->backend->tearDown();
327  }
328  }
329 }
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\initializeObject
‪initializeObject()
Definition: PersistenceManager.php:233
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectDataByQuery
‪array getObjectDataByQuery(QueryInterface $query)
Definition: PersistenceManager.php:106
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\registerRepositoryClassName
‪registerRepositoryClassName($className)
Definition: PersistenceManager.php:85
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectCountByQuery
‪int getObjectCountByQuery(QueryInterface $query)
Definition: PersistenceManager.php:95
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\injectSettings
‪injectSettings(array $settings)
Definition: PersistenceManager.php:224
‪TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
Definition: PersistenceManagerInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$changedObjects
‪ObjectStorage $changedObjects
Definition: PersistenceManager.php:36
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\registerNewObject
‪registerNewObject($object)
Definition: PersistenceManager.php:279
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:29
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\__construct
‪__construct(QueryFactoryInterface $queryFactory, BackendInterface $backend, Session $persistenceSession)
Definition: PersistenceManager.php:65
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\clearState
‪clearState()
Definition: PersistenceManager.php:247
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$queryFactory
‪TYPO3 CMS Extbase Persistence Generic QueryFactoryInterface $queryFactory
Definition: PersistenceManager.php:48
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\isNewObject
‪bool isNewObject($object)
Definition: PersistenceManager.php:262
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\createQueryForType
‪QueryInterface createQueryForType($type)
Definition: PersistenceManager.php:174
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$persistenceSession
‪TYPO3 CMS Extbase Persistence Generic Session $persistenceSession
Definition: PersistenceManager.php:56
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getObjectByIdentifier
‪object getObjectByIdentifier($identifier, $objectType=null, $useLazyLoading=false)
Definition: PersistenceManager.php:136
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$addedObjects
‪ObjectStorage $addedObjects
Definition: PersistenceManager.php:40
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\convertObjectsToIdentityArrays
‪convertObjectsToIdentityArrays(array $array)
Definition: PersistenceManager.php:304
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\update
‪update($object)
Definition: PersistenceManager.php:210
‪TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
Definition: BackendInterface.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface
Definition: QueryFactoryInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:29
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$backend
‪TYPO3 CMS Extbase Persistence Generic BackendInterface $backend
Definition: PersistenceManager.php:52
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:16
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\persistAll
‪persistAll()
Definition: PersistenceManager.php:151
‪TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
Definition: UnknownObjectException.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\tearDown
‪tearDown()
Definition: PersistenceManager.php:316
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$removedObjects
‪ObjectStorage $removedObjects
Definition: PersistenceManager.php:44
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\convertObjectToIdentityArray
‪convertObjectToIdentityArray($object)
Definition: PersistenceManager.php:291
‪TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
Definition: NotImplementedException.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\$newObjects
‪array $newObjects
Definition: PersistenceManager.php:32
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\getIdentifierByObject
‪mixed getIdentifierByObject($object)
Definition: PersistenceManager.php:122
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager\add
‪add($object)
Definition: PersistenceManager.php:184