vendor/shopware/core/System/Language/CachedLanguageLoader.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\Language;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Contracts\Cache\CacheInterface;
  5. class CachedLanguageLoader implements LanguageLoaderInterfaceEventSubscriberInterface
  6. {
  7.     private const CACHE_KEY 'shopware.languages';
  8.     private CacheInterface $cache;
  9.     private LanguageLoaderInterface $loader;
  10.     /**
  11.      * @internal
  12.      */
  13.     public function __construct(LanguageLoaderInterface $loaderCacheInterface $cache)
  14.     {
  15.         $this->cache $cache;
  16.         $this->loader $loader;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             LanguageEvents::LANGUAGE_DELETED_EVENT => 'invalidateCache',
  22.             LanguageEvents::LANGUAGE_WRITTEN_EVENT => 'invalidateCache',
  23.         ];
  24.     }
  25.     public function loadLanguages(): array
  26.     {
  27.         return $this->cache->get(self::CACHE_KEY, function () {
  28.             return $this->loader->loadLanguages();
  29.         });
  30.     }
  31.     public function invalidateCache(): void
  32.     {
  33.         $this->cache->delete(self::CACHE_KEY);
  34.     }
  35. }