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