‪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 
77  public function ‪hasObject(object $object): bool
78  {
79  return $this->objectMap->contains($object);
80  }
81 
88  public function ‪hasIdentifier(string ‪$identifier, string $className): bool
89  {
90  return isset($this->identifierMap[$this->‪getClassIdentifier($className)][‪$identifier]);
91  }
92 
99  public function ‪getObjectByIdentifier(string ‪$identifier, string $className): object
100  {
101  return $this->identifierMap[$this->‪getClassIdentifier($className)][‪$identifier];
102  }
103 
110  public function ‪getIdentifierByObject(object $object): ?string
111  {
112  if ($this->‪hasObject($object)) {
113  return $this->objectMap[$object];
114  }
115  return null;
116  }
117 
123  public function ‪registerObject(object $object, string ‪$identifier): void
124  {
125  $this->objectMap[$object] = ‪$identifier;
126  $this->identifierMap[$this->‪getClassIdentifier(get_class($object))][‪$identifier] = $object;
127  }
128 
132  public function ‪unregisterObject(object $object): void
133  {
134  unset($this->identifierMap[$this->‪getClassIdentifier(get_class($object))][$this->objectMap[$object]]);
135  $this->objectMap->detach($object);
136  }
137 
142  public function ‪destroy(): void
143  {
144  $this->identifierMap = [];
145  $this->objectMap = new ‪ObjectStorage();
146  $this->reconstitutedEntities = new ‪ObjectStorage();
147  }
148 
157  protected function ‪getClassIdentifier(string $className): string
158  {
159  return strtolower($className);
160  }
161 }
‪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:123
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\hasObject
‪hasObject(object $object)
Definition: Session.php:77
‪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:132
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getIdentifierByObject
‪non empty string null getIdentifierByObject(object $object)
Definition: Session.php:110
‪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:88
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\destroy
‪destroy()
Definition: Session.php:142
‪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:157
‪TYPO3\CMS\Extbase\Persistence\Generic\Session\getObjectByIdentifier
‪getObjectByIdentifier(string $identifier, string $className)
Definition: Session.php:99
‪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