PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Settings / Storage / UserScopedSettingsAccessManager.php
matomo / app / core / Settings / Storage Last commit date
Backend 1 month ago Factory.php 3 months ago LegacyUserSettingsMigration.php 1 month ago Storage.php 1 year ago UserScopedSettingsAccessManager.php 1 month ago
UserScopedSettingsAccessManager.php
89 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Settings\Storage;
10
11 use Exception;
12 use Piwik\Settings\Storage\Backend\PluginSettingsTable;
13 class UserScopedSettingsAccessManager
14 {
15 /**
16 * @var array<string, PluginSettingsTable>
17 */
18 private $backends = [];
19 /**
20 * @param mixed $defaultValue
21 * @return mixed
22 */
23 public function get(string $pluginName, string $userLogin, string $key, $defaultValue = null)
24 {
25 return $this->getBackend($pluginName, $userLogin)->loadValue($key, $defaultValue);
26 }
27 /**
28 * @param mixed $value
29 */
30 public function set(string $pluginName, string $userLogin, string $key, $value) : void
31 {
32 $this->getBackend($pluginName, $userLogin)->saveValue($key, $value);
33 }
34 public function getAll(string $pluginName, string $userLogin) : array
35 {
36 $this->validatePluginAndLogin($pluginName, $userLogin);
37 return $this->getBackend($pluginName, $userLogin)->load();
38 }
39 public function setAll(string $pluginName, string $userLogin, array $settings) : void
40 {
41 $this->validatePluginAndLogin($pluginName, $userLogin);
42 $this->getBackend($pluginName, $userLogin)->save($settings);
43 }
44 public function delete(string $pluginName, string $userLogin, string $key) : void
45 {
46 $this->getBackend($pluginName, $userLogin)->deleteValue($key);
47 }
48 public function deleteAll(string $pluginName, string $userLogin) : void
49 {
50 $this->validatePluginAndLogin($pluginName, $userLogin);
51 $this->getBackend($pluginName, $userLogin)->delete();
52 }
53 /**
54 * @param string[] $settingNames
55 * @return array<string, array<string, mixed>>
56 */
57 public function getValuesForAllUsers(string $pluginName, array $settingNames) : array
58 {
59 if (empty($pluginName) || empty($settingNames)) {
60 return [];
61 }
62 // login is not used by loadValuesForUsers(), value is irrelevant
63 return $this->getBackend($pluginName, $userLogin = '')->loadValuesForUsers($settingNames);
64 }
65 private function validatePluginAndLogin(string $pluginName, string $userLogin) : void
66 {
67 if (empty($pluginName)) {
68 throw new \Exception('No plugin name specified for user scoped settings store');
69 }
70 if (empty($userLogin)) {
71 throw new \Exception('No username specified for user scoped settings store');
72 }
73 }
74 /**
75 * @throws Exception when $pluginName is empty
76 */
77 private function getBackend(string $pluginName, string $userLogin) : PluginSettingsTable
78 {
79 if (empty($pluginName)) {
80 throw new \Exception('No plugin name specified for user scoped settings store');
81 }
82 $id = $pluginName . '#' . $userLogin;
83 if (empty($this->backends[$id])) {
84 $this->backends[$id] = new PluginSettingsTable($pluginName, $userLogin);
85 }
86 return $this->backends[$id];
87 }
88 }
89