TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Session.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
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 
82  public function registerReconstitutedEntity($entity, array $entityData = [])
83  {
84  $this->reconstitutedEntities->attach($entity);
85  $this->reconstitutedEntitiesData[$entityData['identifier']] = $entityData;
86  }
87 
95  public function replaceReconstitutedEntity($oldEntity, $newEntity)
96  {
97  $this->reconstitutedEntities->detach($oldEntity);
98  $this->reconstitutedEntities->attach($newEntity);
99  }
100 
107  public function unregisterReconstitutedEntity($entity)
108  {
109  if ($this->reconstitutedEntities->contains($entity)) {
110  $this->reconstitutedEntities->detach($entity);
111  unset($this->reconstitutedEntitiesData[$this->getIdentifierByObject($entity)]);
112  }
113  }
114 
120  public function getReconstitutedEntities()
121  {
123  }
124 
131  public function isReconstitutedEntity($entity)
132  {
133  return $this->reconstitutedEntities->contains($entity);
134  }
135 
136  // @todo implement the is dirty checking behaviour of the Flow persistence session here
137 
145  public function hasObject($object)
146  {
147  return $this->objectMap->contains($object);
148  }
149 
157  public function hasIdentifier($identifier, $className)
158  {
159  return isset($this->identifierMap[strtolower($className)][$identifier]);
160  }
161 
170  public function getObjectByIdentifier($identifier, $className)
171  {
172  return $this->identifierMap[strtolower($className)][$identifier];
173  }
174 
184  public function getIdentifierByObject($object)
185  {
186  if ($this->hasObject($object)) {
187  return $this->objectMap[$object];
188  }
189  return null;
190  }
191 
199  public function registerObject($object, $identifier)
200  {
201  $this->objectMap[$object] = $identifier;
202  $this->identifierMap[strtolower(get_class($object))][$identifier] = $object;
203  }
204 
211  public function unregisterObject($object)
212  {
213  unset($this->identifierMap[strtolower(get_class($object))][$this->objectMap[$object]]);
214  $this->objectMap->detach($object);
215  }
216 
223  public function destroy()
224  {
225  $this->identifierMap = [];
226  $this->objectMap = new ObjectStorage();
227  $this->reconstitutedEntities = new ObjectStorage();
228  $this->reconstitutedEntitiesData = [];
229  }
230 }
hasIdentifier($identifier, $className)
Definition: Session.php:157
getObjectByIdentifier($identifier, $className)
Definition: Session.php:170
injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
Definition: Session.php:58
replaceReconstitutedEntity($oldEntity, $newEntity)
Definition: Session.php:95
registerReconstitutedEntity($entity, array $entityData=[])
Definition: Session.php:82