Browse Source
Merge pull request #20782 from nextcloud/enh/appframework/appconfig_wrapper
Merge pull request #20782 from nextcloud/enh/appframework/appconfig_wrapper
Simple AppConfig wrapper for the AppFrameworkpull/20854/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 193 additions and 0 deletions
-
2lib/composer/composer/autoload_classmap.php
-
2lib/composer/composer/autoload_static.php
-
3lib/private/AppFramework/DependencyInjection/DIContainer.php
-
75lib/private/AppFramework/Services/AppConfig.php
-
111lib/public/AppFramework/Services/IAppConfig.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); |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue