X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FLocaleProjectStorage.php;fp=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FLocaleProjectStorage.php;h=05faa17db31e15408fd63d954faebb68ee8b257e;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/locale/src/LocaleProjectStorage.php b/web/core/modules/locale/src/LocaleProjectStorage.php new file mode 100644 index 000000000..05faa17db --- /dev/null +++ b/web/core/modules/locale/src/LocaleProjectStorage.php @@ -0,0 +1,169 @@ +keyValueStore = $key_value_factory->get('locale.project'); + } + + /** + * {@inheritdoc} + */ + public function get($key, $default = NULL) { + $values = $this->getMultiple([$key]); + return isset($values[$key]) ? $values[$key] : $default; + } + + /** + * {@inheritdoc} + */ + public function getMultiple(array $keys) { + $values = []; + $load = []; + foreach ($keys as $key) { + // Check if we have a value in the cache. + if (isset($this->cache[$key])) { + $values[$key] = $this->cache[$key]; + } + // Load the value if we don't have an explicit NULL value. + elseif (!array_key_exists($key, $this->cache)) { + $load[] = $key; + } + } + + if ($load) { + $loaded_values = $this->keyValueStore->getMultiple($load); + foreach ($load as $key) { + // If we find a value, even one that is NULL, add it to the cache and + // return it. + if (isset($loaded_values[$key])) { + $values[$key] = $loaded_values[$key]; + $this->cache[$key] = $loaded_values[$key]; + } + else { + $this->cache[$key] = NULL; + } + } + } + + return $values; + } + + /** + * {@inheritdoc} + */ + public function set($key, $value) { + $this->setMultiple([$key => $value]); + } + + /** + * {@inheritdoc} + */ + public function setMultiple(array $data) { + foreach ($data as $key => $value) { + $this->cache[$key] = $value; + } + $this->keyValueStore->setMultiple($data); + } + + /** + * {@inheritdoc} + */ + public function delete($key) { + $this->deleteMultiple([$key]); + } + + /** + * {@inheritdoc} + */ + public function deleteMultiple(array $keys) { + foreach ($keys as $key) { + $this->cache[$key] = NULL; + } + $this->keyValueStore->deleteMultiple($keys); + } + + /** + * {@inheritdoc} + */ + public function resetCache() { + $this->cache = []; + static::$all = FALSE; + } + + /** + * {@inheritdoc} + */ + public function deleteAll() { + $this->keyValueStore->deleteAll(); + $this->resetCache(); + } + + /** + * {@inheritdoc} + */ + public function disableAll() { + $projects = $this->keyValueStore->getAll(); + foreach (array_keys($projects) as $key) { + $projects[$key]['status'] = 0; + if (isset($cache[$key])) { + $cache[$key] = $projects[$key]; + } + } + $this->keyValueStore->setMultiple($projects); + + } + + /** + * {@inheritdoc} + */ + public function countProjects() { + return count($this->getAll()); + } + + /** + * {@inheritdoc} + */ + public function getAll() { + if (!static::$all) { + $this->cache = $this->keyValueStore->getAll(); + static::$all = TRUE; + } + return $this->cache; + } + +}