summaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-05-02 15:34:28 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2020-05-02 15:34:28 +0200
commit8a8623c569169696a77b3d492538ef28c89bcda0 (patch)
treee50b49979b579cf4dd26b8796d6b023c2b566876 /lib/private/AppFramework
parent8910a1ffcba8d78831a238d170700e8ace3e0979 (diff)
downloadnextcloud-server-8a8623c569169696a77b3d492538ef28c89bcda0.tar.gz
nextcloud-server-8a8623c569169696a77b3d492538ef28c89bcda0.zip
Simple AppConfig wrapper for the AppFramework
9 out of 10 cases apps want to access their own appconfig. Hence it would be nice not to have to enter the app id all the time. This simple wrapper just passes on the appid in all calls. Basically this allows for simpler code in the apps. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php3
-rw-r--r--lib/private/AppFramework/Services/AppConfig.php75
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 6654d3849b2..e0c6571787e 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -52,6 +52,7 @@ use OCA\WorkflowEngine\Manager;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\Folder;
@@ -293,6 +294,8 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, OC\Collaboration\Resources\ProviderManager::class);
$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, OC\Collaboration\Resources\Manager::class);
+
+ $this->registerAlias(IAppConfig::class, OC\AppFramework\Services\AppConfig::class);
}
/**
diff --git a/lib/private/AppFramework/Services/AppConfig.php b/lib/private/AppFramework/Services/AppConfig.php
new file mode 100644
index 00000000000..4716313b342
--- /dev/null
+++ b/lib/private/AppFramework/Services/AppConfig.php
@@ -0,0 +1,75 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\AppFramework\Services;
+
+use OCP\AppFramework\Services\IAppConfig;
+use OCP\IConfig;
+
+class AppConfig implements IAppConfig {
+
+ /** @var IConfig */
+ private $config;
+
+ /** @var string */
+ private $appName;
+
+ public function __construct(IConfig $config, string $appName) {
+ $this->config = $config;
+ $this->appName = $appName;
+ }
+
+ public function getAppKeys(): array {
+ return $this->config->getAppKeys($this->appName);
+ }
+
+ public function setAppValue(string $key, string $value): void {
+ $this->config->setAppValue($this->appName, $key, $value);
+ }
+
+ public function getAppValue(string $key, string $default = ''): string {
+ return $this->config->getAppValue($this->appName, $key, $default);
+ }
+
+ public function deleteAppValue(string $key): void {
+ $this->config->deleteAppValue($this->appName, $key);
+ }
+
+ public function deleteAppValues(): void {
+ $this->config->deleteAppValues($this->appName);
+ }
+
+ public function setUserValue(string $userId, string $key, string $value, ?string $preCondition = null): void {
+ $this->config->setUserValue($userId, $this->appName, $key, $value, $preCondition);
+ }
+
+ public function getUserValue(string $userId, string $key, string $default = ''): string {
+ return $this->config->getUserValue($userId, $this->appName, $key, $default);
+ }
+
+ public function deleteUserValue(string $userId, string $key): void {
+ return $this->config->deleteUserValue($userId, $this->appName, $key);
+ }
+}