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); + } +}