‪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  #[AsEventListener]
36  public function ‪warmupCaches(‪CacheWarmupEvent $event): void
37  {
38  if ($event->‪hasGroup('system')) {
39  ‪$languages = $this->locales->getActiveLanguages();
40  $packages = $this->packageManager->getActivePackages();
41  foreach ($packages as $package) {
42  ‪$dir = $package->getPackagePath() . 'Resources/Private/Language';
43  if (!is_dir(‪$dir)) {
44  continue;
45  }
46  $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(‪$dir));
47  // Search for all files with suffix *.xlf and without a dot in the file basename
48  $fileIterator = new \RegexIterator($recursiveIterator, '#^.+/[^.]+\.xlf$#', \RegexIterator::GET_MATCH);
49  $shorthand = 'EXT:' . $package->getPackageKey() . '/Resources/Private/Language';
50  foreach ($fileIterator as $match) {
51  $fileReference = str_replace(‪$dir, $shorthand, $match[0]);
52  foreach (‪$languages as $language) {
53  // @todo: Force cache renewal
54  $this->localizationFactory->getParsedData($fileReference, $language);
55  }
56  }
57  }
58  }
59  }
60 }
‪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:36
‪$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:36
‪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:34