‪TYPO3CMS  9.5
Session.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 
18 
24 {
28  protected ‪$objectContainer;
29 
35  protected ‪$reconstitutedEntities;
36 
40  protected ‪$objectMap;
41 
45  protected ‪$identifierMap = [];
46 
50  public function ‪__construct(\‪TYPO3\CMS\‪Extbase\Object\Container\Container $container)
51  {
52  $this->objectContainer = $container;
53  $this->reconstitutedEntities = new ‪ObjectStorage();
54  $this->objectMap = new ‪ObjectStorage();
55  }
56 
65  public function ‪registerReconstitutedEntity($entity)
66  {
67  $this->reconstitutedEntities->attach($entity);
68  }
69 
76  public function ‪replaceReconstitutedEntity($oldEntity, $newEntity)
77  {
78  $this->reconstitutedEntities->detach($oldEntity);
79  $this->reconstitutedEntities->attach($newEntity);
80  }
81 
87  public function ‪unregisterReconstitutedEntity($entity)
88  {
89  if ($this->reconstitutedEntities->contains($entity)) {
90  $this->reconstitutedEntities->detach($entity);
91  }
92  }
93 
99  public function ‪getReconstitutedEntities()
100  {
102  }
103 
110  public function ‪isReconstitutedEntity($entity)
111  {
112  return $this->reconstitutedEntities->contains($entity);
113  }
114 
115  // @todo implement the is dirty checking behaviour of the Flow persistence session here
116 
123  public function ‪hasObject($object)
124  {
125  return $this->objectMap->contains($object);
126  }
127 
135  public function ‪hasIdentifier($identifier, $className)
136  {
137  return isset($this->identifierMap[$this->‪getClassIdentifier($className)][$identifier]);
138  }
139 
147  public function ‪getObjectByIdentifier($identifier, $className)
148  {
149  return $this->identifierMap[$this->‪getClassIdentifier($className)][$identifier];
150  }
151 
160  public function ‪getIdentifierByObject($object)
161  {
162  if ($this->‪hasObject($object)) {
163  return $this->objectMap[$object];
164  }
165  return null;
166  }
167 
174  public function ‪registerObject($object, $identifier)
175  {
176  $this->objectMap[$object] = $identifier;
177  $this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$identifier] = $object;
178  }
179 
185  public function ‪unregisterObject($object)
186  {
187  unset($this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$this->objectMap[$object]]);
188  $this->objectMap->detach($object);
189  }
190 
195  public function ‪destroy()
196  {
197  $this->identifierMap = [];
198  $this->objectMap = new ObjectStorage();
199  $this->reconstitutedEntities = new ObjectStorage();
200  }
201 
209  protected function ‪getClassIdentifier($className): string
210  {
211  return strtolower($this->objectContainer->getImplementationClassName($className));
212  }
213 }
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getIdentifierByObject
‪string getIdentifierByObject($object)
Definition: Session.php:156
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getReconstitutedEntities
‪ObjectStorage getReconstitutedEntities()
Definition: Session.php:95
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$objectMap
‪ObjectStorage $objectMap
Definition: Session.php:37
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterReconstitutedEntity
‪unregisterReconstitutedEntity($entity)
Definition: Session.php:83
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$identifierMap
‪array $identifierMap
Definition: Session.php:41
‪TYPO3
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getClassIdentifier
‪string getClassIdentifier($className)
Definition: Session.php:205
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerObject
‪registerObject($object, $identifier)
Definition: Session.php:170
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:26
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\__construct
‪__construct(\TYPO3\CMS\Extbase\Object\Container\Container $container)
Definition: Session.php:46
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$reconstitutedEntities
‪ObjectStorage $reconstitutedEntities
Definition: Session.php:33
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getObjectByIdentifier
‪object getObjectByIdentifier($identifier, $className)
Definition: Session.php:143
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerReconstitutedEntity
‪registerReconstitutedEntity($entity)
Definition: Session.php:61
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterObject
‪unregisterObject($object)
Definition: Session.php:181
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:24
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\destroy
‪destroy()
Definition: Session.php:191
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\replaceReconstitutedEntity
‪replaceReconstitutedEntity($oldEntity, $newEntity)
Definition: Session.php:72
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:2
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$objectContainer
‪TYPO3 CMS Extbase Object Container Container $objectContainer
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\isReconstitutedEntity
‪bool isReconstitutedEntity($entity)
Definition: Session.php:106
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasObject
‪bool hasObject($object)
Definition: Session.php:119
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasIdentifier
‪bool hasIdentifier($identifier, $className)
Definition: Session.php:131