Extends CacheArray to allow for dynamic building of the locale cache.
Expanded class hierarchy of LocaleLookup
class LocaleLookup extends CacheArray {
/**
* A language code.
* @var string
*/
protected $langcode;
/**
* The msgctxt context.
* @var string
*/
protected $context;
/**
* The locale storage
*
* @var Drupal\locale\StringStorageInterface
*/
protected $stringStorage;
/**
* Constructs a LocaleCache object.
*/
public function __construct($langcode, $context, $stringStorage) {
$this->langcode = $langcode;
$this->context = (string) $context;
$this->stringStorage = $stringStorage;
// Add the current user's role IDs to the cache key, this ensures that, for
// example, strings for admin menu items and settings forms are not cached
// for anonymous users.
$rids = implode(':', array_keys($GLOBALS['user']->roles));
parent::__construct("locale:{$langcode}:{$context}:{$rids}", 'cache', array(
'locale' => TRUE,
));
}
/**
* Implements CacheArray::resolveCacheMiss().
*/
protected function resolveCacheMiss($offset) {
$translation = $this->stringStorage
->findTranslation(array(
'language' => $this->langcode,
'source' => $offset,
'context' => $this->context,
));
if ($translation) {
$value = !empty($translation->translation) ? $translation->translation : TRUE;
}
else {
// We don't have the source string, update the {locales_source} table to
// indicate the string is not translated.
$this->stringStorage
->createString(array(
'source' => $offset,
'context' => $this->context,
'version' => VERSION,
))
->addLocation('path', request_uri())
->save();
$value = TRUE;
}
$this->storage[$offset] = $value;
// Disabling the usage of string caching allows a module to watch for
// the exact list of strings used on a page. From a performance
// perspective that is a really bad idea, so we have no user
// interface for this. Be careful when turning this option off!
if (variable_get('locale_cache_strings', 1)) {
$this
->persist($offset);
}
return $value;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheArray:: |
protected | property | A bin to pass to cache()->set() and cache()->get(). | |
CacheArray:: |
protected | property | A cid to pass to cache()->set() and cache()->get(). | |
CacheArray:: |
protected | property | An array of keys to add to the cache at the end of the request. | |
CacheArray:: |
protected | property | Storage for the data itself. | |
CacheArray:: |
protected | property | A tags array to pass to cache()->set(). | |
CacheArray:: |
public | function | Implements ArrayAccess::offsetExists(). | 1 |
CacheArray:: |
public | function | Implements ArrayAccess::offsetGet(). | 1 |
CacheArray:: |
public | function | Implements ArrayAccess::offsetSet(). | |
CacheArray:: |
public | function | Implements ArrayAccess::offsetUnset(). | |
CacheArray:: |
protected | function | Flags an offset value to be written to the persistent cache. | |
CacheArray:: |
protected | function | Writes a value to the persistent cache immediately. | 1 |
CacheArray:: |
public | function | Destructs the CacheArray object. | |
LocaleLookup:: |
protected | property | The msgctxt context. | |
LocaleLookup:: |
protected | property | A language code. | |
LocaleLookup:: |
protected | property | The locale storage | |
LocaleLookup:: |
protected | function |
Implements CacheArray::resolveCacheMiss(). Overrides CacheArray:: |
|
LocaleLookup:: |
public | function |
Constructs a LocaleCache object. Overrides CacheArray:: |