TYPO3 CMS  TYPO3_8-7
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 
23 {
30 
39 
43  protected $objectMap;
44 
48  protected $identifierMap = [];
49 
53  protected $reflectionService;
54 
58  public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
59  {
60  $this->reflectionService = $reflectionService;
61  }
62 
66  public function __construct()
67  {
68  $this->reconstitutedEntities = new ObjectStorage();
69  $this->objectMap = new ObjectStorage();
70  }
71 
81  public function registerReconstitutedEntity($entity, array $entityData = [])
82  {
83  $this->reconstitutedEntities->attach($entity);
84  $this->reconstitutedEntitiesData[$entityData['identifier']] = $entityData;
85  }
86 
93  public function replaceReconstitutedEntity($oldEntity, $newEntity)
94  {
95  $this->reconstitutedEntities->detach($oldEntity);
96  $this->reconstitutedEntities->attach($newEntity);
97  }
98 
104  public function unregisterReconstitutedEntity($entity)
105  {
106  if ($this->reconstitutedEntities->contains($entity)) {
107  $this->reconstitutedEntities->detach($entity);
108  unset($this->reconstitutedEntitiesData[$this->getIdentifierByObject($entity)]);
109  }
110  }
111 
117  public function getReconstitutedEntities()
118  {
120  }
121 
128  public function isReconstitutedEntity($entity)
129  {
130  return $this->reconstitutedEntities->contains($entity);
131  }
132 
133  // @todo implement the is dirty checking behaviour of the Flow persistence session here
134 
142  public function hasObject($object)
143  {
144  return $this->objectMap->contains($object);
145  }
146 
154  public function hasIdentifier($identifier, $className)
155  {
156  return isset($this->identifierMap[strtolower($className)][$identifier]);
157  }
158 
167  public function getObjectByIdentifier($identifier, $className)
168  {
169  return $this->identifierMap[strtolower($className)][$identifier];
170  }
171 
181  public function getIdentifierByObject($object)
182  {
183  if ($this->hasObject($object)) {
184  return $this->objectMap[$object];
185  }
186  return null;
187  }
188 
196  public function registerObject($object, $identifier)
197  {
198  $this->objectMap[$object] = $identifier;
199  $this->identifierMap[strtolower(get_class($object))][$identifier] = $object;
200  }
201 
207  public function unregisterObject($object)
208  {
209  unset($this->identifierMap[strtolower(get_class($object))][$this->objectMap[$object]]);
210  $this->objectMap->detach($object);
211  }
212 
217  public function destroy()
218  {
219  $this->identifierMap = [];
220  $this->objectMap = new ObjectStorage();
221  $this->reconstitutedEntities = new ObjectStorage();
222  $this->reconstitutedEntitiesData = [];
223  }
224 }
registerReconstitutedEntity($entity, array $entityData=[])
Definition: Session.php:81
replaceReconstitutedEntity($oldEntity, $newEntity)
Definition: Session.php:93
injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
Definition: Session.php:58
getObjectByIdentifier($identifier, $className)
Definition: Session.php:167
hasIdentifier($identifier, $className)
Definition: Session.php:154