Elgg  Version 4.3
PrivateSettingsCache.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cache;
4 
5 use ElggCache;
7 use Elgg\Values;
8 
15 
19  protected $cache;
20 
26  public function __construct(ElggCache $cache) {
27  $this->cache = $cache;
28  }
29 
37  public function load($key) {
38  return $this->cache->load($key);
39  }
40 
50  public function save($key, $data, $expire_after = null) {
51  return $this->cache->save($key, $data, $expire_after);
52  }
53 
60  public function populateFromEntities(...$guids) {
61  try {
63  } catch (DataFormatException $e) {
64  return null;
65  }
66 
67  if (empty($guids)) {
68  return null;
69  }
70 
71  $cached_values = [];
72 
73  foreach ($guids as $i => $guid) {
74  $value = $this->load($guid);
75  if ($value !== null) {
76  $cached_values[$guid] = $value;
77  unset($guids[$i]);
78  }
79  }
80 
81  if (empty($guids)) {
82  return $cached_values;
83  }
84 
85  $data = _elgg_services()->privateSettings->getAllForGUIDs($guids);
86 
87  // store always for every guid, even if there is no settings
88  foreach ($guids as $guid) {
89  $settings = elgg_extract($guid, $data, []);
90 
91  $this->save($guid, $settings);
92  $cached_values[$guid] = $settings;
93  }
94 
95  return $cached_values;
96  }
97 }
static normalizeGuids(...$args)
Flatten an array of data into an array of GUIDs.
Definition: Values.php:141
Saves user notification settings.
save($key, $data, $expire_after=null)
Save data in a cache.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
__construct(ElggCache $cache)
Constructor.
if($type!= 'user') $settings
Definition: save.php:16
$value
Definition: generic.php:51
load($key)
Load data from the cache using a given key.
In memory cache of known private settings values stored by entity.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
An exception thrown when there is a problem in the format of some data.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
populateFromEntities(...$guids)
Populate the cache from a set of entities.
$guid
Reset an ElggUpgrade.
Definition: reset.php:6