Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-05-07 09:43:55 +0300
committerGitHub <noreply@github.com>2020-05-07 09:43:55 +0300
commite923d7b42f920cf80a9605a75b2414e07aec7263 (patch)
treeac0467123b9a82afe9c4fa980e5c755c4686c393 /lib
parent97f36e62f2bc2dc35db184bc7ab4f3969280510c (diff)
parent8a8623c569169696a77b3d492538ef28c89bcda0 (diff)
Merge pull request #20782 from nextcloud/enh/appframework/appconfig_wrapper
Simple AppConfig wrapper for the AppFramework
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php3
-rw-r--r--lib/private/AppFramework/Services/AppConfig.php75
-rw-r--r--lib/public/AppFramework/Services/IAppConfig.php111
5 files changed, 193 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 7a4bf0ad846..3599d03fc67 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -69,6 +69,7 @@ return array(
'OCP\\AppFramework\\OCS\\OCSNotFoundException' => $baseDir . '/lib/public/AppFramework/OCS/OCSNotFoundException.php',
'OCP\\AppFramework\\PublicShareController' => $baseDir . '/lib/public/AppFramework/PublicShareController.php',
'OCP\\AppFramework\\QueryException' => $baseDir . '/lib/public/AppFramework/QueryException.php',
+ 'OCP\\AppFramework\\Services\\IAppConfig' => $baseDir . '/lib/public/AppFramework/Services/IAppConfig.php',
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => $baseDir . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
'OCP\\AppFramework\\Utility\\ITimeFactory' => $baseDir . '/lib/public/AppFramework/Utility/ITimeFactory.php',
'OCP\\App\\AppPathNotFoundException' => $baseDir . '/lib/public/App/AppPathNotFoundException.php',
@@ -556,6 +557,7 @@ return array(
'OC\\AppFramework\\OCS\\V2Response' => $baseDir . '/lib/private/AppFramework/OCS/V2Response.php',
'OC\\AppFramework\\Routing\\RouteActionHandler' => $baseDir . '/lib/private/AppFramework/Routing/RouteActionHandler.php',
'OC\\AppFramework\\Routing\\RouteConfig' => $baseDir . '/lib/private/AppFramework/Routing/RouteConfig.php',
+ 'OC\\AppFramework\\Services\\AppConfig' => $baseDir . '/lib/private/AppFramework/Services/AppConfig.php',
'OC\\AppFramework\\Utility\\ControllerMethodReflector' => $baseDir . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php',
'OC\\AppFramework\\Utility\\SimpleContainer' => $baseDir . '/lib/private/AppFramework/Utility/SimpleContainer.php',
'OC\\AppFramework\\Utility\\TimeFactory' => $baseDir . '/lib/private/AppFramework/Utility/TimeFactory.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index ab2f1ffa56f..fcdbf82bfb7 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -98,6 +98,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\AppFramework\\OCS\\OCSNotFoundException' => __DIR__ . '/../../..' . '/lib/public/AppFramework/OCS/OCSNotFoundException.php',
'OCP\\AppFramework\\PublicShareController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/PublicShareController.php',
'OCP\\AppFramework\\QueryException' => __DIR__ . '/../../..' . '/lib/public/AppFramework/QueryException.php',
+ 'OCP\\AppFramework\\Services\\IAppConfig' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Services/IAppConfig.php',
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
'OCP\\AppFramework\\Utility\\ITimeFactory' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/ITimeFactory.php',
'OCP\\App\\AppPathNotFoundException' => __DIR__ . '/../../..' . '/lib/public/App/AppPathNotFoundException.php',
@@ -585,6 +586,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\AppFramework\\OCS\\V2Response' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/V2Response.php',
'OC\\AppFramework\\Routing\\RouteActionHandler' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteActionHandler.php',
'OC\\AppFramework\\Routing\\RouteConfig' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteConfig.php',
+ 'OC\\AppFramework\\Services\\AppConfig' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Services/AppConfig.php',
'OC\\AppFramework\\Utility\\ControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php',
'OC\\AppFramework\\Utility\\SimpleContainer' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/SimpleContainer.php',
'OC\\AppFramework\\Utility\\TimeFactory' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/TimeFactory.php',
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);
+ }
+}
diff --git a/lib/public/AppFramework/Services/IAppConfig.php b/lib/public/AppFramework/Services/IAppConfig.php
new file mode 100644
index 00000000000..84c9b6466b8
--- /dev/null
+++ b/lib/public/AppFramework/Services/IAppConfig.php
@@ -0,0 +1,111 @@
+<?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 OCP\AppFramework\Services;
+
+/**
+ * Wrapper for AppConfig for the AppFramework
+ *
+ * @since 20.0.0
+ */
+interface IAppConfig {
+ /**
+ * Get all keys stored for this app
+ *
+ * @return string[] the keys stored for the app
+ * @since 20.0.0
+ */
+ public function getAppKeys(): array ;
+
+ /**
+ * Writes a new app wide value
+ *
+ * @param string $key the key of the value, under which will be saved
+ * @param string $value the value that should be stored
+ * @return void
+ * @since 20.0.0
+ */
+ public function setAppValue(string $key, string $value): void;
+
+ /**
+ * Looks up an app wide defined value
+ *
+ * @param string $key the key of the value, under which it was saved
+ * @param string $default the default value to be returned if the value isn't set
+ * @return string the saved value
+ * @since 20.0.0
+ */
+ public function getAppValue(string $key, string $default = ''): string;
+
+ /**
+ * Delete an app wide defined value
+ *
+ * @param string $key the key of the value, under which it was saved
+ * @return void
+ * @since 20.0.0
+ */
+ public function deleteAppValue(string $key): void;
+
+ /**
+ * Removes all keys in appconfig belonging to the app
+ *
+ * @return void
+ * @since 20.0.0
+ */
+ public function deleteAppValues(): void;
+
+ /**
+ * Set a user defined value
+ *
+ * @param string $userId the userId of the user that we want to store the value under
+ * @param string $key the key under which the value is being stored
+ * @param string $value the value that you want to store
+ * @param string $preCondition only update if the config value was previously the value passed as $preCondition
+ * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
+ * @throws \UnexpectedValueException when trying to store an unexpected value
+ * @since 20.0.0
+ */
+ public function setUserValue(string $userId, string $key, string $value, ?string $preCondition = null): void;
+
+ /**
+ * Shortcut for getting a user defined value
+ *
+ * @param string $userId the userId of the user that we want to store the value under
+ * @param string $key the key under which the value is being stored
+ * @param mixed $default the default value to be returned if the value isn't set
+ * @return string
+ * @since 20.0.0
+ */
+ public function getUserValue(string $userId, string $key, string $default = ''): string;
+
+ /**
+ * Delete a user value
+ *
+ * @param string $userId the userId of the user that we want to store the value under
+ * @param string $key the key under which the value is being stored
+ * @since 20.0.0
+ */
+ public function deleteUserValue(string $userId, string $key): void;
+}