ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilCachedLanguage Class Reference

Class ilCachedLanguage. More...

+ Inheritance diagram for ilCachedLanguage:
+ Collaboration diagram for ilCachedLanguage:

Public Member Functions

 getContainerKey ()
 
 isForced ()
 
 isActive ()
 Return whether the global cache is active. More...
 
 writeToCache ()
 Write to global cache. More...
 
 deleteInCache ()
 Delete the cache entry for this language without flushing the whole global cache Using this function avoids a flush loop when languages are updated A missing entry will cause the next request to refill the cache in the constructor of this class. More...
 
 flush ()
 
 setLanguageKey (string $language_key)
 Set language key. More...
 
 getLanguageKey ()
 Return language key. More...
 
 setLoaded (bool $loaded)
 
 getLoaded ()
 
 setTranslations (array $translations)
 Set translations. More...
 
 getTranslations ()
 Return translations as array. More...
 
 getContainerKey ()
 
 isForced ()
 

Static Public Member Functions

static getInstance ($key)
 

Protected Member Functions

 __construct (string $language_key)
 ilCachedLanguage constructor. More...
 
 readFromCache ()
 Read from cache. More...
 
 readFromDB ()
 Read data from table lng_module from DB. More...
 

Protected Attributes

ILIAS Cache Container Container $language_cache
 
bool $loaded = false
 
string $language_key = "en"
 
array $translations = array()
 

Static Protected Attributes

static array $instances = array()
 

Detailed Description

Class ilCachedLanguage.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 30 of file class.ilCachedLanguage.php.

Constructor & Destructor Documentation

◆ __construct()

ilCachedLanguage::__construct ( string  $language_key)
protected

ilCachedLanguage constructor.

Definition at line 41 of file class.ilCachedLanguage.php.

42 {
43 global $DIC;
45 $this->language_cache = $DIC->globalCache()->get($this);
46 $this->readFromCache();
47 if (!$this->getLoaded()) {
48 $this->readFromDB();
49 $this->writeToCache();
50 $this->setLoaded(true);
51 }
52 }
readFromDB()
Read data from table lng_module from DB.
setLanguageKey(string $language_key)
Set language key.
readFromCache()
Read from cache.
writeToCache()
Write to global cache.
global $DIC
Definition: shib_login.php:26

References $DIC, getLoaded(), readFromCache(), readFromDB(), setLanguageKey(), setLoaded(), and writeToCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteInCache()

ilCachedLanguage::deleteInCache ( )

Delete the cache entry for this language without flushing the whole global cache Using this function avoids a flush loop when languages are updated A missing entry will cause the next request to refill the cache in the constructor of this class.

See also
mantis #28818

Definition at line 115 of file class.ilCachedLanguage.php.

115 : void
116 {
117 $this->language_cache->delete("translations_" . $this->getLanguageKey());
118 $this->setLoaded(false);
119 }
getLanguageKey()
Return language key.

References getLanguageKey(), and setLoaded().

+ Here is the call graph for this function:

◆ flush()

ilCachedLanguage::flush ( )

Definition at line 154 of file class.ilCachedLanguage.php.

154 : void
155 {
156 $this->language_cache->flush();
157 $this->readFromDB();
158 $this->writeToCache();
159 }

References readFromDB(), and writeToCache().

+ Here is the call graph for this function:

◆ getContainerKey()

ilCachedLanguage::getContainerKey ( )

Implements ILIAS\Cache\Container\Request.

Definition at line 54 of file class.ilCachedLanguage.php.

54 : string
55 {
56 return 'clng';
57 }

◆ getInstance()

static ilCachedLanguage::getInstance (   $key)
static

Definition at line 145 of file class.ilCachedLanguage.php.

145 : self
146 {
147 if (!isset(self::$instances[$key])) {
148 self::$instances[$key] = new self($key);
149 }
150
151 return self::$instances[$key];
152 }

Referenced by ilLanguage\__construct(), and ILIAS\Language\Setup\TranslationCacheLegacyProxy\invalidate().

+ Here is the caller graph for this function:

◆ getLanguageKey()

ilCachedLanguage::getLanguageKey ( )

Return language key.

Definition at line 172 of file class.ilCachedLanguage.php.

172 : string
173 {
174 return $this->language_key;
175 }

References $language_key.

Referenced by deleteInCache(), readFromCache(), readFromDB(), and writeToCache().

+ Here is the caller graph for this function:

◆ getLoaded()

ilCachedLanguage::getLoaded ( )

Definition at line 182 of file class.ilCachedLanguage.php.

182 : bool
183 {
184 return $this->loaded;
185 }

References $loaded.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getTranslations()

ilCachedLanguage::getTranslations ( )

Return translations as array.

Definition at line 198 of file class.ilCachedLanguage.php.

198 : array
199 {
200 return $this->translations;
201 }

References $translations.

Referenced by writeToCache().

+ Here is the caller graph for this function:

◆ isActive()

ilCachedLanguage::isActive ( )

Return whether the global cache is active.

Always true, so cached_modules is always filled: ilLanguage::loadLanguageModule() must check the PO/MO overlay of a migrated module before cached_modules, or the DB cache hides the overlay.

Definition at line 71 of file class.ilCachedLanguage.php.

71 : bool
72 {
73 return true;
74 }

◆ isForced()

ilCachedLanguage::isForced ( )

Implements ILIAS\Cache\Container\Request.

Definition at line 60 of file class.ilCachedLanguage.php.

60 : bool
61 {
62 return true;
63 }

◆ readFromCache()

ilCachedLanguage::readFromCache ( )
protected

Read from cache.

Definition at line 79 of file class.ilCachedLanguage.php.

79 : void
80 {
81 $key = "translations_" . $this->getLanguageKey();
82 if ($this->language_cache->has($key)) {
83 // This is a workaround for the fact that transformatuin cannot be created by
84 // $DIC->refinery()->xy() since we are in a hell of dependencies. E.g. we cant instantiate the
85 // caching service with $DIC->refinery() since the Refinery needs ilLanguage, but ilLanguage
86 // needs the caching service and so on...
87 $always = new Transformation(
88 function ($v) {
89 return is_array($v) ? $v : null;
90 }
91 );
92
93 $translations = $this->language_cache->get($key, $always);
94 if (is_array($translations)) {
95 $this->setTranslations($translations);
96 $this->setLoaded(true);
97 }
98 }
99 }
Transform values according to custom configuration.
setTranslations(array $translations)
Set translations.

References $translations, getLanguageKey(), setLoaded(), and setTranslations().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFromDB()

ilCachedLanguage::readFromDB ( )
protected

Read data from table lng_module from DB.

Definition at line 124 of file class.ilCachedLanguage.php.

124 : void
125 {
126 global $DIC;
127 $ilDB = $DIC->database();
128
129 $q = 'SELECT module, lang_array FROM lng_modules WHERE lang_key = %s';
130 $res = $ilDB->queryF($q, array( "text" ), array( $this->getLanguageKey() ));
131 $translations = array();
132 while ($set = $ilDB->fetchObject($res)) {
133 try {
134 $lang_array = unserialize($set->lang_array, ['allowed_classes' => false]);
135 } catch (Throwable $t) {
136 continue;
137 }
138 if (is_array($lang_array)) {
139 $translations[$set->module] = $lang_array;
140 }
141 }
143 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $res, $translations, getLanguageKey(), and setTranslations().

Referenced by __construct(), and flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLanguageKey()

ilCachedLanguage::setLanguageKey ( string  $language_key)

Set language key.

Definition at line 164 of file class.ilCachedLanguage.php.

164 : void
165 {
166 $this->language_key = $language_key;
167 }

References $language_key.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLoaded()

ilCachedLanguage::setLoaded ( bool  $loaded)

Definition at line 177 of file class.ilCachedLanguage.php.

177 : void
178 {
179 $this->loaded = $loaded;
180 }

References $loaded.

Referenced by __construct(), deleteInCache(), and readFromCache().

+ Here is the caller graph for this function:

◆ setTranslations()

ilCachedLanguage::setTranslations ( array  $translations)

Set translations.

Definition at line 190 of file class.ilCachedLanguage.php.

190 : void
191 {
192 $this->translations = $translations;
193 }

References $translations.

Referenced by readFromCache(), and readFromDB().

+ Here is the caller graph for this function:

◆ writeToCache()

ilCachedLanguage::writeToCache ( )

Write to global cache.

Definition at line 104 of file class.ilCachedLanguage.php.

104 : void
105 {
106 $this->language_cache->set("translations_" . $this->getLanguageKey(), $this->getTranslations());
107 }
getTranslations()
Return translations as array.

References getLanguageKey(), and getTranslations().

Referenced by __construct(), and flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $instances

array ilCachedLanguage::$instances = array()
staticprotected

Definition at line 36 of file class.ilCachedLanguage.php.

◆ $language_cache

ILIAS Cache Container Container ilCachedLanguage::$language_cache
protected

Definition at line 32 of file class.ilCachedLanguage.php.

◆ $language_key

string ilCachedLanguage::$language_key = "en"
protected

Definition at line 34 of file class.ilCachedLanguage.php.

Referenced by getLanguageKey(), and setLanguageKey().

◆ $loaded

bool ilCachedLanguage::$loaded = false
protected

Definition at line 33 of file class.ilCachedLanguage.php.

Referenced by getLoaded(), and setLoaded().

◆ $translations

array ilCachedLanguage::$translations = array()
protected

The documentation for this class was generated from the following file: