From 7b5e92f83e4e1f9a3f157055e616634a798e7249 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 22 Sep 2020 14:24:48 +0200 Subject: [PATCH] add config proxy --- lib/Service/ConfigProxy.php | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/Service/ConfigProxy.php diff --git a/lib/Service/ConfigProxy.php b/lib/Service/ConfigProxy.php new file mode 100644 index 0000000..9b94d31 --- /dev/null +++ b/lib/Service/ConfigProxy.php @@ -0,0 +1,65 @@ + + */ +class ConfigProxy +{ + /** + * @var IConfig + */ + protected $config; + + public function __construct(IConfig $config) + { + $this->config = $config; + } + + public function getAppValue(string $name, string $default): string + { + return (string) $this->config->getAppValue(Application::APP_ID, $name, $default); + } + + public function getUserValue(User $user, string $name, string $default): string + { + return (string) $this->config->getUserValue($user->getUid(), Application::APP_ID, $name, $default); + } + + public function getAppValueBool(string $name, string $default): bool + { + return (bool) $this->getAppValue($name, $default); + } + + public function getAppValueArray(string $name, string $default): array + { + return (array) json_decode($this->getAppValue($name, $default), true); + } + + public function getAppValueInt(string $name, string $default): int + { + return (int) $this->getAppValue($name, $default); + } + + public function getUserValueBool(User $user, string $name, string $default): bool + { + return (bool) $this->getUserValue($user, $name, $default); + } + + public function getUserValueArray(User $user, string $name, string $default): array + { + return (array) json_decode($this->getUserValue($user, $name, $default), true); + } + + public function getUserValueInt(User $user, string $name, string $default): int + { + return (int) $this->getUserValue($user, $name, $default); + } +}