‪TYPO3CMS  10.4
Session.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 
21 
27 {
31  protected ‪$objectContainer;
32 
38  protected ‪$reconstitutedEntities;
39 
43  protected ‪$objectMap;
44 
48  protected ‪$identifierMap = [];
49 
53  public function ‪__construct(‪Container $container)
54  {
55  $this->objectContainer = $container;
56  $this->reconstitutedEntities = new ‪ObjectStorage();
57  $this->objectMap = new ‪ObjectStorage();
58  }
59 
68  public function ‪registerReconstitutedEntity($entity)
69  {
70  $this->reconstitutedEntities->attach($entity);
71  }
72 
79  public function ‪replaceReconstitutedEntity($oldEntity, $newEntity)
80  {
81  $this->reconstitutedEntities->detach($oldEntity);
82  $this->reconstitutedEntities->attach($newEntity);
83  }
84 
90  public function ‪unregisterReconstitutedEntity($entity)
91  {
92  if ($this->reconstitutedEntities->contains($entity)) {
93  $this->reconstitutedEntities->detach($entity);
94  }
95  }
96 
102  public function ‪getReconstitutedEntities()
103  {
105  }
106 
113  public function ‪isReconstitutedEntity($entity)
114  {
115  return $this->reconstitutedEntities->contains($entity);
116  }
117 
118  // @todo implement the is dirty checking behaviour of the Flow persistence session here
119 
126  public function ‪hasObject($object)
127  {
128  return $this->objectMap->contains($object);
129  }
130 
138  public function ‪hasIdentifier($identifier, $className)
139  {
140  return isset($this->identifierMap[$this->‪getClassIdentifier($className)][$identifier]);
141  }
142 
150  public function ‪getObjectByIdentifier($identifier, $className)
151  {
152  return $this->identifierMap[$this->‪getClassIdentifier($className)][$identifier];
153  }
154 
163  public function ‪getIdentifierByObject($object)
164  {
165  if ($this->‪hasObject($object)) {
166  return $this->objectMap[$object];
167  }
168  return null;
169  }
170 
177  public function ‪registerObject($object, $identifier)
178  {
179  $this->objectMap[$object] = $identifier;
180  $this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$identifier] = $object;
181  }
182 
188  public function ‪unregisterObject($object)
189  {
190  unset($this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$this->objectMap[$object]]);
191  $this->objectMap->detach($object);
192  }
193 
198  public function ‪destroy()
199  {
200  $this->identifierMap = [];
201  $this->objectMap = new ObjectStorage();
202  $this->reconstitutedEntities = new ObjectStorage();
203  }
204 
212  protected function ‪getClassIdentifier($className): string
213  {
214  return strtolower($this->objectContainer->getImplementationClassName($className));
215  }
216 }
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getIdentifierByObject
‪string getIdentifierByObject($object)
Definition: Session.php:159
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getReconstitutedEntities
‪ObjectStorage getReconstitutedEntities()
Definition: Session.php:98
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\__construct
‪__construct(Container $container)
Definition: Session.php:49
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$objectMap
‪ObjectStorage $objectMap
Definition: Session.php:40
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:39
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterReconstitutedEntity
‪unregisterReconstitutedEntity($entity)
Definition: Session.php:86
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$identifierMap
‪array $identifierMap
Definition: Session.php:44
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getClassIdentifier
‪string getClassIdentifier($className)
Definition: Session.php:208
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerObject
‪registerObject($object, $identifier)
Definition: Session.php:173
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$reconstitutedEntities
‪ObjectStorage $reconstitutedEntities
Definition: Session.php:36
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getObjectByIdentifier
‪object getObjectByIdentifier($identifier, $className)
Definition: Session.php:146
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerReconstitutedEntity
‪registerReconstitutedEntity($entity)
Definition: Session.php:64
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterObject
‪unregisterObject($object)
Definition: Session.php:184
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\destroy
‪destroy()
Definition: Session.php:194
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\replaceReconstitutedEntity
‪replaceReconstitutedEntity($oldEntity, $newEntity)
Definition: Session.php:75
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:16
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$objectContainer
‪TYPO3 CMS Extbase Object Container Container $objectContainer
Definition: Session.php:30
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\isReconstitutedEntity
‪bool isReconstitutedEntity($entity)
Definition: Session.php:109
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasObject
‪bool hasObject($object)
Definition: Session.php:122
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasIdentifier
‪bool hasIdentifier($identifier, $className)
Definition: Session.php:134