‪TYPO3CMS  ‪main
CacheWarmer.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  protected readonly PackageManager $packageManager,
31  protected readonly ‪Locales $locales,
32  protected readonly ‪LocalizationFactory $localizationFactory
33  ) {
34  }
35 
36  #[AsEventListener]
37  public function ‪warmupCaches(‪CacheWarmupEvent $event): void
38  {
39  if ($event->‪hasGroup('system')) {
40  ‪$languages = $this->locales->getActiveLanguages();
41  $packages = $this->packageManager->getActivePackages();
42  foreach ($packages as $package) {
43  ‪$dir = $package->getPackagePath() . 'Resources/Private/Language';
44  if (!is_dir(‪$dir)) {
45  continue;
46  }
47  $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(‪$dir));
48  // Search for all files with suffix *.xlf and without a dot in the file basename
49  $fileIterator = new \RegexIterator($recursiveIterator, '#^.+/[^.]+\.xlf$#', \RegexIterator::GET_MATCH);
50  $shorthand = 'EXT:' . $package->getPackageKey() . '/Resources/Private/Language';
51  foreach ($fileIterator as $match) {
52  $fileReference = str_replace(‪$dir, $shorthand, $match[0]);
53  foreach (‪$languages as $language) {
54  // @todo: Force cache renewal
55  $this->localizationFactory->getParsedData($fileReference, $language);
56  }
57  }
58  }
59  }
60  }
61 }
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:31
‪$languages
‪$languages
Definition: updateIsoDatabase.php:104
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:33
‪$dir
‪$dir
Definition: validateRstFiles.php:257
‪TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent
Definition: CacheWarmupEvent.php:24
‪TYPO3\CMS\Core\Localization
Definition: CacheWarmer.php:18
‪TYPO3\CMS\Core\Localization\CacheWarmer
Definition: CacheWarmer.php:28
‪TYPO3\CMS\Core\Localization\CacheWarmer\warmupCaches
‪warmupCaches(CacheWarmupEvent $event)
Definition: CacheWarmer.php:37
‪TYPO3\CMS\Core\Localization\CacheWarmer\__construct
‪__construct(protected readonly PackageManager $packageManager, protected readonly Locales $locales, protected readonly LocalizationFactory $localizationFactory)
Definition: CacheWarmer.php:29
‪TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent\hasGroup
‪hasGroup(string $group)
Definition: CacheWarmupEvent.php:36