‪TYPO3CMS  ‪main
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 {
29  private string ‪$cacheIdentifier;
30 
34  protected ‪$dataCache;
35 
44  protected ‪$dataCacheNeedsUpdate = false;
45 
51  protected ‪$classSchemata = [];
52 
53  public function ‪__construct(‪FrontendInterface $cache, string ‪$cacheIdentifier)
54  {
55  $this->dataCache = $cache;
56  $this->cacheIdentifier = ‪$cacheIdentifier;
57  if ((‪$classSchemata = $this->dataCache->get($this->cacheIdentifier)) !== false) {
58  $this->classSchemata = ‪$classSchemata;
59  }
60  }
61 
62  public function ‪__destruct()
63  {
64  if ($this->dataCacheNeedsUpdate) {
65  $this->dataCache->set($this->cacheIdentifier, $this->classSchemata);
66  }
67  }
68 
75  public function ‪getClassSchema($classNameOrObject): ClassSchema
76  {
77  $className = is_object($classNameOrObject) ? get_class($classNameOrObject) : $classNameOrObject;
78  if (isset($this->classSchemata[$className])) {
79  return $this->classSchemata[$className];
80  }
81 
82  return $this->‪buildClassSchema($className);
83  }
84 
92  protected function ‪buildClassSchema($className): ClassSchema
93  {
94  try {
95  $classSchema = new ClassSchema($className);
96  } catch (\ReflectionException $e) {
97  throw new UnknownClassException($e->getMessage() . '. Reflection failed.', 1278450972, $e);
98  }
99  $this->classSchemata[$className] = $classSchema;
100  $this->dataCacheNeedsUpdate = true;
101  return $classSchema;
102  }
103 
107  public function ‪__sleep(): array
108  {
109  return [];
110  }
111 
115  public function ‪__wakeup(): void
116  {
117  $this->dataCache = new NullFrontend('extbase');
118  $this->dataCacheNeedsUpdate = false;
119  $this->cacheIdentifier = '';
120  $this->classSchemata = [];
121  }
122 }
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$cacheIdentifier
‪string $cacheIdentifier
Definition: ReflectionService.php:29
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$dataCacheNeedsUpdate
‪bool $dataCacheNeedsUpdate
Definition: ReflectionService.php:42
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\buildClassSchema
‪ClassSchema buildClassSchema($className)
Definition: ReflectionService.php:89
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:30
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__destruct
‪__destruct()
Definition: ReflectionService.php:59
‪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:104
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\getClassSchema
‪getClassSchema($classNameOrObject)
Definition: ReflectionService.php:72
‪TYPO3\CMS\Extbase\Reflection
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$classSchemata
‪array $classSchemata
Definition: ReflectionService.php:48
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\$dataCache
‪FrontendInterface $dataCache
Definition: ReflectionService.php:33
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__wakeup
‪__wakeup()
Definition: ReflectionService.php:112
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Reflection\ReflectionService\__construct
‪__construct(FrontendInterface $cache, string $cacheIdentifier)
Definition: ReflectionService.php:50
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:50