‪TYPO3CMS  ‪main
ExtTablesFactory.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 
22 use TYPO3\CMS\Core\Package\PackageManager;
23 
28 {
29  public function ‪__construct(
30  private readonly PackageManager $packageManager,
31  private readonly ‪PhpFrontend $codeCache,
32  ) {}
33 
38  public function ‪load(): void
39  {
40  $cacheIdentifier = $this->‪getExtTablesCacheIdentifier();
41  $hasCache = $this->codeCache->require($cacheIdentifier) !== false;
42  if (!$hasCache) {
44  $this->‪createCacheEntry();
45  }
46  }
47 
48  public function ‪loadUncached(): void
49  {
51  }
52 
56  public function ‪createCacheEntry(): void
57  {
58  $phpCodeToCache = [];
59  $phpCodeToCache[] = '';
62  // Iterate through loaded extensions and add ext_tables content
63  foreach ($this->packageManager->getActivePackages() as $package) {
64  $extensionKey = $package->getPackageKey();
65  $extTablesPath = $package->getPackagePath() . 'ext_tables.php';
66  if (@file_exists($extTablesPath)) {
67  // Include a header per extension to make the cache file more readable
68  $phpCodeToCache[] = '';
72  // Add ext_tables.php content of extension
73  $phpCodeToCache[] = 'namespace {';
74  $phpCodeToCache[] = trim((string)file_get_contents($extTablesPath));
75  $phpCodeToCache[] = '}';
76  $phpCodeToCache[] = '';
77  $phpCodeToCache[] = '';
78  }
79  }
80  $phpCodeToCache = implode(LF, $phpCodeToCache);
81  // Remove all start and ending php tags from content, and remove strict_types=1 declaration.
82  $phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
83  $phpCodeToCache = preg_replace('/declare\\s?+\\(\\s?+strict_types\\s?+=\\s?+1\\s?+\\);/is', '', (string)$phpCodeToCache);
84  $this->codeCache->set($this->‪getExtTablesCacheIdentifier(), $phpCodeToCache);
85  }
86 
90  private function ‪loadSingleExtTablesFiles(): void
91  {
92  foreach ($this->packageManager->getActivePackages() as $package) {
93  $extTablesPath = $package->getPackagePath() . 'ext_tables.php';
94  if (file_exists($extTablesPath)) {
95  require $extTablesPath;
96  }
97  }
98  }
99 
103  private function ‪getExtTablesCacheIdentifier(): string
104  {
105  return (new ‪PackageDependentCacheIdentifier($this->packageManager))->withPrefix('ext_tables')->toString();
106  }
107 }
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\createCacheEntry
‪createCacheEntry()
Definition: ExtTablesFactory.php:56
‪TYPO3\CMS\Core\Configuration\Extension
Definition: ExtLocalconfFactory.php:18
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\__construct
‪__construct(private readonly PackageManager $packageManager, private readonly PhpFrontend $codeCache,)
Definition: ExtTablesFactory.php:29
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:25
‪TYPO3\CMS\Core\Package\Cache\PackageDependentCacheIdentifier
Definition: PackageDependentCacheIdentifier.php:30
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\load
‪load()
Definition: ExtTablesFactory.php:38
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\loadUncached
‪loadUncached()
Definition: ExtTablesFactory.php:48
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory
Definition: ExtTablesFactory.php:28
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\loadSingleExtTablesFiles
‪loadSingleExtTablesFiles()
Definition: ExtTablesFactory.php:90
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory\getExtTablesCacheIdentifier
‪getExtTablesCacheIdentifier()
Definition: ExtTablesFactory.php:103