ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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...
 

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.

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

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  }
setLanguageKey(string $language_key)
Set language key.
writeToCache()
Write to global cache.
global $DIC
Definition: shib_login.php:22
readFromDB()
Read data from table lng_module from DB.
readFromCache()
Read from cache.
+ 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 112 of file class.ilCachedLanguage.php.

References getLanguageKey(), and setLoaded().

112  : void
113  {
114  $this->language_cache->delete("translations_" . $this->getLanguageKey());
115  $this->setLoaded(false);
116  }
getLanguageKey()
Return language key.
+ Here is the call graph for this function:

◆ flush()

ilCachedLanguage::flush ( )

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

References readFromDB(), and writeToCache().

151  : void
152  {
153  $this->language_cache->flush();
154  $this->readFromDB();
155  $this->writeToCache();
156  }
writeToCache()
Write to global cache.
readFromDB()
Read data from table lng_module from DB.
+ 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 142 of file class.ilCachedLanguage.php.

Referenced by ilLanguage\__construct(), ilObjLanguageExt\_saveValues(), ilObjLanguage\replaceLangModule(), and ilObjLanguageDBAccess\replaceLangModules().

142  : self
143  {
144  if (!isset(self::$instances[$key])) {
145  self::$instances[$key] = new self($key);
146  }
147 
148  return self::$instances[$key];
149  }
+ Here is the caller graph for this function:

◆ getLanguageKey()

ilCachedLanguage::getLanguageKey ( )

Return language key.

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

References $language_key.

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

169  : string
170  {
171  return $this->language_key;
172  }
+ Here is the caller graph for this function:

◆ getLoaded()

ilCachedLanguage::getLoaded ( )

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

References $loaded.

Referenced by __construct().

179  : bool
180  {
181  return $this->loaded;
182  }
+ Here is the caller graph for this function:

◆ getTranslations()

ilCachedLanguage::getTranslations ( )

Return translations as array.

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

References $translations.

Referenced by writeToCache().

195  : array
196  {
197  return $this->translations;
198  }
+ Here is the caller graph for this function:

◆ isActive()

ilCachedLanguage::isActive ( )

Return whether the global cache is active.

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

68  : bool
69  {
70  return true;
71  }

◆ 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 76 of file class.ilCachedLanguage.php.

References getLanguageKey(), null, setLoaded(), and setTranslations().

Referenced by __construct().

76  : void
77  {
78  $key = "translations_" . $this->getLanguageKey();
79  if ($this->language_cache->has($key)) {
80  // This is a workaround for the fact that transformatuin cannot be created by
81  // $DIC->refinery()->xy() since we are in a hell of dependencies. E.g. we cant instantiate the
82  // caching service with $DIC->refinery() since the Refinery needs ilLanguage, but ilLanguage
83  // needs the caching service and so on...
84  $always = new Transformation(
85  function ($v) {
86  return is_array($v) ? $v : null;
87  }
88  );
89 
90  $translations = $this->language_cache->get($key, $always);
91  if (is_array($translations)) {
92  $this->setTranslations($translations);
93  $this->setLoaded(true);
94  }
95  }
96  }
Transform values according to custom configuration.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getLanguageKey()
Return language key.
setTranslations(array $translations)
Set translations.
+ 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 121 of file class.ilCachedLanguage.php.

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

Referenced by __construct(), and flush().

121  : void
122  {
123  global $DIC;
124  $ilDB = $DIC->database();
125 
126  $q = 'SELECT module, lang_array FROM lng_modules WHERE lang_key = %s';
127  $res = $ilDB->queryF($q, array( "text" ), array( $this->getLanguageKey() ));
128  $translations = array();
129  while ($set = $ilDB->fetchObject($res)) {
130  try {
131  $lang_array = unserialize($set->lang_array, ['allowed_classes' => false]);
132  } catch (Throwable $t) {
133  continue;
134  }
135  if (is_array($lang_array)) {
136  $translations[$set->module] = $lang_array;
137  }
138  }
140  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
$q
Definition: shib_logout.php:21
getLanguageKey()
Return language key.
setTranslations(array $translations)
Set translations.
+ 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 161 of file class.ilCachedLanguage.php.

References $language_key.

Referenced by __construct().

161  : void
162  {
163  $this->language_key = $language_key;
164  }
+ Here is the caller graph for this function:

◆ setLoaded()

ilCachedLanguage::setLoaded ( bool  $loaded)

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

References $loaded.

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

174  : void
175  {
176  $this->loaded = $loaded;
177  }
+ Here is the caller graph for this function:

◆ setTranslations()

ilCachedLanguage::setTranslations ( array  $translations)

Set translations.

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

References $translations.

Referenced by readFromCache(), and readFromDB().

187  : void
188  {
189  $this->translations = $translations;
190  }
+ Here is the caller graph for this function:

◆ writeToCache()

ilCachedLanguage::writeToCache ( )

Write to global cache.

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

References getLanguageKey(), and getTranslations().

Referenced by __construct(), and flush().

101  : void
102  {
103  $this->language_cache->set("translations_" . $this->getLanguageKey(), $this->getTranslations());
104  }
getTranslations()
Return translations as array.
getLanguageKey()
Return language key.
+ 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

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

Referenced by getTranslations(), and setTranslations().


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