‪TYPO3CMS  11.5
ReflectionService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
28 {
32  private string ‪$cacheIdentifier;
33 
37  protected ‪$dataCache;
38 
47  protected ‪$dataCacheNeedsUpdate = false;
48 
54  protected ‪$classSchemata = [];
55 
56  public function ‪__construct(‪FrontendInterface $cache, string ‪$cacheIdentifier)
57  {
58  $this->dataCache = $cache;
59  $this->cacheIdentifier = ‪$cacheIdentifier;
60  if ((‪$classSchemata = $this->dataCache->get($this->cacheIdentifier)) !== false) {
61  $this->classSchemata = ‪$classSchemata;
62  }
63  }
64 
65  public function ‪__destruct()
66  {
67  if ($this->dataCacheNeedsUpdate) {
68  $this->dataCache->set($this->cacheIdentifier, $this->classSchemata);
69  }
70  }
71 
79  public function ‪getClassSchema($classNameOrObject): ClassSchema
80  {
81  $className = is_object($classNameOrObject) ? get_class($classNameOrObject) : $classNameOrObject;
82  if (isset($this->classSchemata[$className])) {
83  return $this->classSchemata[$className];
84  }
85 
86  return $this->‪buildClassSchema($className);
87  }
88 
96  protected function ‪buildClassSchema($className): ClassSchema
97  {
98  try {
99  $classSchema = new ClassSchema($className);
100  } catch (\ReflectionException $e) {
101  throw new UnknownClassException($e->getMessage() . '. Reflection failed.', 1278450972, $e);
102  }
103  $this->classSchemata[$className] = $classSchema;
104  $this->dataCacheNeedsUpdate = true;
105  return $classSchema;
106  }
107 
111  public function ‪__sleep(): array
112  {
113  return [];
114  }
115 
119  public function ‪__wakeup(): void
120  {
121  $this->dataCache = new NullFrontend('extbase');
122  $this->dataCacheNeedsUpdate = false;
123  $this->cacheIdentifier = '';
124  $this->classSchemata = [];
125  }
126 }
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$cacheIdentifier
‪string $cacheIdentifier
Definition: ReflectionService.php:32
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$dataCacheNeedsUpdate
‪bool $dataCacheNeedsUpdate
Definition: ReflectionService.php:45
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\buildClassSchema
‪ClassSchema buildClassSchema($className)
Definition: ReflectionService.php:93
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:29
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\getClassSchema
‪ClassSchema getClassSchema($classNameOrObject)
Definition: ReflectionService.php:76
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__destruct
‪__destruct()
Definition: ReflectionService.php:62
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:28
‪TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException
Definition: UnknownClassException.php:25
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__sleep
‪__sleep()
Definition: ReflectionService.php:108
‪TYPO3\CMS\Extbase\Reflection
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$classSchemata
‪array $classSchemata
Definition: ReflectionService.php:51
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$dataCache
‪FrontendInterface $dataCache
Definition: ReflectionService.php:36
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__wakeup
‪__wakeup()
Definition: ReflectionService.php:116
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__construct
‪__construct(FrontendInterface $cache, string $cacheIdentifier)
Definition: ReflectionService.php:53
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:54