| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Settings\Storage; |
|
|
| use Exception; |
| use Piwik\Settings\Storage\Backend\PluginSettingsTable; |
|
|
| class UserScopedSettingsAccessManager |
| { |
| |
| |
| |
| private $backends = []; |
|
|
| |
| |
| |
| |
| public function get(string $pluginName, string $userLogin, string $key, $defaultValue = null) |
| { |
| return $this->getBackend($pluginName, $userLogin)->loadValue($key, $defaultValue); |
| } |
|
|
| |
| |
| |
| public function set(string $pluginName, string $userLogin, string $key, $value): void |
| { |
| $this->getBackend($pluginName, $userLogin)->saveValue($key, $value); |
| } |
|
|
| public function getAll(string $pluginName, string $userLogin): array |
| { |
| $this->validatePluginAndLogin($pluginName, $userLogin); |
| return $this->getBackend($pluginName, $userLogin)->load(); |
| } |
|
|
| public function setAll(string $pluginName, string $userLogin, array $settings): void |
| { |
| $this->validatePluginAndLogin($pluginName, $userLogin); |
| $this->getBackend($pluginName, $userLogin)->save($settings); |
| } |
|
|
| public function delete(string $pluginName, string $userLogin, string $key): void |
| { |
| $this->getBackend($pluginName, $userLogin)->deleteValue($key); |
| } |
|
|
| public function deleteAll(string $pluginName, string $userLogin): void |
| { |
| $this->validatePluginAndLogin($pluginName, $userLogin); |
| $this->getBackend($pluginName, $userLogin)->delete(); |
| } |
|
|
| |
| |
| |
| |
| public function getValuesForAllUsers(string $pluginName, array $settingNames): array |
| { |
| if (empty($pluginName) || empty($settingNames)) { |
| return []; |
| } |
|
|
| |
| return $this->getBackend($pluginName, $userLogin = '')->loadValuesForUsers($settingNames); |
| } |
|
|
| private function validatePluginAndLogin(string $pluginName, string $userLogin): void |
| { |
| if (empty($pluginName)) { |
| throw new \Exception('No plugin name specified for user scoped settings store'); |
| } |
|
|
| if (empty($userLogin)) { |
| throw new \Exception('No username specified for user scoped settings store'); |
| } |
| } |
|
|
| |
| |
| |
| private function getBackend(string $pluginName, string $userLogin): PluginSettingsTable |
| { |
| if (empty($pluginName)) { |
| throw new \Exception('No plugin name specified for user scoped settings store'); |
| } |
|
|
| $id = $pluginName . '#' . $userLogin; |
| if (empty($this->backends[$id])) { |
| $this->backends[$id] = new PluginSettingsTable($pluginName, $userLogin); |
| } |
| return $this->backends[$id]; |
| } |
| } |
|
|