‪TYPO3CMS  ‪main
Session.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
27 {
30 
34  protected array ‪$identifierMap = [];
35 
39  public function ‪__construct()
40  {
41  $this->reconstitutedEntities = new ‪ObjectStorage();
42  $this->objectMap = new ‪ObjectStorage();
43  }
44 
51  public function ‪registerReconstitutedEntity(object $entity): void
52  {
53  $this->reconstitutedEntities->attach($entity);
54  }
55 
59  public function ‪unregisterReconstitutedEntity(object $entity): void
60  {
61  if ($this->reconstitutedEntities->contains($entity)) {
62  $this->reconstitutedEntities->detach($entity);
63  }
64  }
65 
70  {
72  }
73 
74  // @todo implement the is dirty checking behaviour of the Flow persistence session here
75 
79  public function ‪hasObject(object $object): bool
80  {
81  return $this->objectMap->contains($object);
82  }
83 
90  public function ‪hasIdentifier(string ‪$identifier, string $className): bool
91  {
92  return isset($this->identifierMap[$this->‪getClassIdentifier($className)][‪$identifier]);
93  }
94 
101  public function ‪getObjectByIdentifier(string ‪$identifier, string $className): object
102  {
103  return $this->identifierMap[$this->‪getClassIdentifier($className)][‪$identifier];
104  }
105 
112  public function ‪getIdentifierByObject(object $object): string|null
113  {
114  if ($this->‪hasObject($object)) {
115  return $this->objectMap[$object];
116  }
117  return null;
118  }
119 
125  public function ‪registerObject(object $object, string ‪$identifier): void
126  {
127  $this->objectMap[$object] = ‪$identifier;
128  $this->identifierMap[$this->‪getClassIdentifier(get_class($object))][‪$identifier] = $object;
129  }
130 
134  public function ‪unregisterObject(object $object): void
135  {
136  unset($this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$this->objectMap[$object]]);
137  $this->objectMap->detach($object);
138  }
139 
144  public function ‪destroy(): void
145  {
146  $this->identifierMap = [];
147  $this->objectMap = new ‪ObjectStorage();
148  $this->reconstitutedEntities = new ‪ObjectStorage();
149  }
150 
159  protected function ‪getClassIdentifier(string $className): string
160  {
161  return strtolower($className);
162  }
163 }
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$objectMap
‪ObjectStorage $objectMap
Definition: Session.php:29
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$identifierMap
‪array $identifierMap
Definition: Session.php:34
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerObject
‪registerObject(object $object, string $identifier)
Definition: Session.php:125
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasObject
‪hasObject(object $object)
Definition: Session.php:79
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\__construct
‪__construct()
Definition: Session.php:39
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:34
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterObject
‪unregisterObject(object $object)
Definition: Session.php:134
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getIdentifierByObject
‪non empty string null getIdentifierByObject(object $object)
Definition: Session.php:112
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\$reconstitutedEntities
‪ObjectStorage $reconstitutedEntities
Definition: Session.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getReconstitutedEntities
‪getReconstitutedEntities()
Definition: Session.php:69
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\registerReconstitutedEntity
‪registerReconstitutedEntity(object $entity)
Definition: Session.php:51
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasIdentifier
‪hasIdentifier(string $identifier, string $className)
Definition: Session.php:90
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\destroy
‪destroy()
Definition: Session.php:144
‪TYPO3\CMS\Extbase\Persistence\Generic
Definition: Backend.php:18
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getClassIdentifier
‪non empty string getClassIdentifier(string $className)
Definition: Session.php:159
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getObjectByIdentifier
‪getObjectByIdentifier(string $identifier, string $className)
Definition: Session.php:101
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\unregisterReconstitutedEntity
‪unregisterReconstitutedEntity(object $entity)
Definition: Session.php:59