aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-02-01 19:51:47 -0100
committerGitHub <noreply@github.com>2024-02-01 19:51:47 -0100
commitb838237f82c627f23c21379d8a899ed70a1790fb (patch)
tree70ca655875101b8354ec8bff0666b114cd8537ab /lib
parent937a6a84fe9fbdbd8e3494f25d92a4e0fbc76376 (diff)
parent31c1bc1c62d8cec10bd7d2651ae184d060fb3f45 (diff)
downloadnextcloud-server-b838237f82c627f23c21379d8a899ed70a1790fb.tar.gz
nextcloud-server-b838237f82c627f23c21379d8a899ed70a1790fb.zip
Merge pull request #43132 from nextcloud/enh/41755/update-appframework-api
sync with new OCP\IAppConfig
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php1
-rw-r--r--lib/private/AppFramework/Services/AppConfig.php309
-rw-r--r--lib/public/AppFramework/Services/IAppConfig.php233
3 files changed, 529 insertions, 14 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index c342ea236e2..93365582864 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -345,6 +345,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService(IAppConfig::class, function (ContainerInterface $c) {
return new OC\AppFramework\Services\AppConfig(
$c->get(IConfig::class),
+ $c->get(\OCP\IAppConfig::class),
$c->get('AppName')
);
});
diff --git a/lib/private/AppFramework/Services/AppConfig.php b/lib/private/AppFramework/Services/AppConfig.php
index 1fc07bc22b0..1d18baef9ed 100644
--- a/lib/private/AppFramework/Services/AppConfig.php
+++ b/lib/private/AppFramework/Services/AppConfig.php
@@ -26,39 +26,322 @@ declare(strict_types=1);
*/
namespace OC\AppFramework\Services;
+use InvalidArgumentException;
+use JsonException;
use OCP\AppFramework\Services\IAppConfig;
+use OCP\Exceptions\AppConfigTypeConflictException;
+use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IConfig;
class AppConfig implements IAppConfig {
- /** @var IConfig */
- private $config;
+ public function __construct(
+ private IConfig $config,
+ /** @var \OC\AppConfig */
+ private \OCP\IAppConfig $appConfig,
+ private string $appName,
+ ) {
+ }
- /** @var string */
- private $appName;
+ /**
+ * @inheritDoc
+ *
+ * @return string[] list of stored config keys
+ * @since 20.0.0
+ */
+ public function getAppKeys(): array {
+ return $this->appConfig->getKeys($this->appName);
+ }
- public function __construct(IConfig $config, string $appName) {
- $this->config = $config;
- $this->appName = $appName;
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param bool|null $lazy TRUE to search within lazy loaded config, NULL to search within all config
+ *
+ * @return bool TRUE if key exists
+ * @since 29.0.0
+ */
+ public function hasAppKey(string $key, ?bool $lazy = false): bool {
+ return $this->appConfig->hasKey($this->appName, $key, $lazy);
}
- public function getAppKeys(): array {
- return $this->config->getAppKeys($this->appName);
+ /**
+ * @param string $key config key
+ * @param bool|null $lazy TRUE to search within lazy loaded config, NULL to search within all config
+ *
+ * @return bool
+ * @throws AppConfigUnknownKeyException if config key is not known
+ * @since 29.0.0
+ */
+ public function isSensitive(string $key, ?bool $lazy = false): bool {
+ return $this->appConfig->isSensitive($this->appName, $key, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ *
+ * @return bool TRUE if config is lazy loaded
+ * @throws AppConfigUnknownKeyException if config key is not known
+ * @see \OCP\IAppConfig for details about lazy loading
+ * @since 29.0.0
+ */
+ public function isLazy(string $key): bool {
+ return $this->appConfig->isLazy($this->appName, $key);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config keys prefix to search
+ * @param bool $filtered TRUE to hide sensitive config values. Value are replaced by {@see IConfig::SENSITIVE_VALUE}
+ *
+ * @return array<string, string> [configKey => configValue]
+ * @since 29.0.0
+ */
+ public function getAllAppValues(string $key = '', bool $filtered = false): array {
+ return $this->appConfig->getAllValues($this->appName, $key, $filtered);
}
+ /**
+ * @inheritDoc
+ *
+ * @param string $key the key of the value, under which will be saved
+ * @param string $value the value that should be stored
+ * @since 20.0.0
+ * @deprecated 29.0.0 use {@see setAppValueString()}
+ */
public function setAppValue(string $key, string $value): void {
- $this->config->setAppValue($this->appName, $key, $value);
+ /** @psalm-suppress InternalMethod */
+ $this->appConfig->setValueMixed($this->appName, $key, $value);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param string $value config value
+ * @param bool $lazy set config as lazy loaded
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @throws AppConfigTypeConflictException if type from database is not VALUE_MIXED and different from the requested one
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueString(
+ string $key,
+ string $value,
+ bool $lazy = false,
+ bool $sensitive = false
+ ): bool {
+ return $this->appConfig->setValueString($this->appName, $key, $value, $lazy, $sensitive);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param int $value config value
+ * @param bool $lazy set config as lazy loaded
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @throws AppConfigTypeConflictException if type from database is not VALUE_MIXED and different from the requested one
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueInt(
+ string $key,
+ int $value,
+ bool $lazy = false,
+ bool $sensitive = false
+ ): bool {
+ return $this->appConfig->setValueInt($this->appName, $key, $value, $lazy, $sensitive);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param float $value config value
+ * @param bool $lazy set config as lazy loaded
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @throws AppConfigTypeConflictException if type from database is not VALUE_MIXED and different from the requested one
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueFloat(
+ string $key,
+ float $value,
+ bool $lazy = false,
+ bool $sensitive = false
+ ): bool {
+ return $this->appConfig->setValueFloat($this->appName, $key, $value, $lazy, $sensitive);
}
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param bool $value config value
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @throws AppConfigTypeConflictException if type from database is not VALUE_MIXED and different from the requested one
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueBool(
+ string $key,
+ bool $value,
+ bool $lazy = false
+ ): bool {
+ return $this->appConfig->setValueBool($this->appName, $key, $value, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param array $value config value
+ * @param bool $lazy set config as lazy loaded
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @throws AppConfigTypeConflictException if type from database is not VALUE_MIXED and different from the requested one
+ * @throws JsonException
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueArray(
+ string $key,
+ array $value,
+ bool $lazy = false,
+ bool $sensitive = false
+ ): bool {
+ return $this->appConfig->setValueArray($this->appName, $key, $value, $lazy, $sensitive);
+ }
+
+ /**
+ * @param string $key
+ * @param string $default
+ *
+ * @since 20.0.0
+ * @deprecated 29.0.0 use {@see getAppValueString()}
+ * @return string
+ */
public function getAppValue(string $key, string $default = ''): string {
- return $this->config->getAppValue($this->appName, $key, $default);
+ /** @psalm-suppress InternalMethod */
+ /** @psalm-suppress UndefinedInterfaceMethod */
+ return $this->appConfig->getValueMixed($this->appName, $key, $default);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param string $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return string stored config value or $default if not set in database
+ * @throws InvalidArgumentException if one of the argument format is invalid
+ * @throws AppConfigTypeConflictException in case of conflict with the value type set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueString(string $key, string $default = '', bool $lazy = false): string {
+ return $this->appConfig->getValueString($this->appName, $key, $default, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param int $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return int stored config value or $default if not set in database
+ * @throws InvalidArgumentException if one of the argument format is invalid
+ * @throws AppConfigTypeConflictException in case of conflict with the value type set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueInt(string $key, int $default = 0, bool $lazy = false): int {
+ return $this->appConfig->getValueInt($this->appName, $key, $default, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param float $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return float stored config value or $default if not set in database
+ * @throws InvalidArgumentException if one of the argument format is invalid
+ * @throws AppConfigTypeConflictException in case of conflict with the value type set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueFloat(string $key, float $default = 0, bool $lazy = false): float {
+ return $this->appConfig->getValueFloat($this->appName, $key, $default, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param bool $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return bool stored config value or $default if not set in database
+ * @throws InvalidArgumentException if one of the argument format is invalid
+ * @throws AppConfigTypeConflictException in case of conflict with the value type set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueBool(string $key, bool $default = false, bool $lazy = false): bool {
+ return $this->appConfig->getValueBool($this->appName, $key, $default, $lazy);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $key config key
+ * @param array $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return array stored config value or $default if not set in database
+ * @throws InvalidArgumentException if one of the argument format is invalid
+ * @throws AppConfigTypeConflictException in case of conflict with the value type set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueArray(string $key, array $default = [], bool $lazy = false): array {
+ return $this->appConfig->getValueArray($this->appName, $key, $default, $lazy);
}
+ /**
+ * @inheritDoc
+ *
+ * @param string $key the key of the value, under which it was saved
+ * @since 20.0.0
+ */
public function deleteAppValue(string $key): void {
- $this->config->deleteAppValue($this->appName, $key);
+ $this->appConfig->deleteKey($this->appName, $key);
}
+ /**
+ * @inheritDoc
+ *
+ * @since 20.0.0
+ */
public function deleteAppValues(): void {
- $this->config->deleteAppValues($this->appName);
+ $this->appConfig->deleteApp($this->appName);
}
public function setUserValue(string $userId, string $key, string $value, ?string $preCondition = null): void {
diff --git a/lib/public/AppFramework/Services/IAppConfig.php b/lib/public/AppFramework/Services/IAppConfig.php
index baac2946e3c..9340fdd3c32 100644
--- a/lib/public/AppFramework/Services/IAppConfig.php
+++ b/lib/public/AppFramework/Services/IAppConfig.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
*
+ * @author Maxence Lange <maxence@artificial-owl.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
@@ -25,6 +26,8 @@ declare(strict_types=1);
*/
namespace OCP\AppFramework\Services;
+use OCP\Exceptions\AppConfigUnknownKeyException;
+
/**
* Wrapper for AppConfig for the AppFramework
*
@@ -37,7 +40,58 @@ interface IAppConfig {
* @return string[] the keys stored for the app
* @since 20.0.0
*/
- public function getAppKeys(): array ;
+ public function getAppKeys(): array;
+
+ /**
+ * Check if a key exists in the list of stored config values.
+ *
+ * @param string $key config key
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return bool TRUE if key exists
+ * @since 29.0.0
+ */
+ public function hasAppKey(string $key, ?bool $lazy = false): bool;
+
+ /**
+ * best way to see if a value is set as sensitive (not displayed in report)
+ *
+ * @param string $key config key
+ * @param bool|null $lazy search within lazy loaded config
+ *
+ * @return bool TRUE if value is sensitive
+ * @throws AppConfigUnknownKeyException if config key is not known
+ * @since 29.0.0
+ */
+ public function isSensitive(string $key, ?bool $lazy = false): bool;
+
+ /**
+ * Returns if the config key stored in database is lazy loaded
+ *
+ * **WARNING:** ignore lazy filtering, all config values are loaded from database
+ *
+ * @param string $key config key
+ *
+ * @return bool TRUE if config is lazy loaded
+ * @throws AppConfigUnknownKeyException if config key is not known
+ * @see IAppConfig for details about lazy loading
+ * @since 29.0.0
+ */
+ public function isLazy(string $key): bool;
+
+ /**
+ * List all config values from an app with config key starting with $key.
+ * Returns an array with config key as key, stored value as value.
+ *
+ * **WARNING:** ignore lazy filtering, all config values are loaded from database
+ *
+ * @param string $key config keys prefix to search, can be empty.
+ * @param bool $filtered filter sensitive config values
+ *
+ * @return array<string, string> [configKey => configValue]
+ * @since 29.0.0
+ */
+ public function getAllAppValues(string $key = '', bool $filtered = false): array;
/**
* Writes a new app wide value
@@ -46,20 +100,197 @@ interface IAppConfig {
* @param string $value the value that should be stored
* @return void
* @since 20.0.0
+ * @deprecated 29.0.0 use {@see setAppValueString()}
*/
public function setAppValue(string $key, string $value): void;
/**
+ * Store a config key and its value in database
+ *
+ * If config key is already known with the exact same config value, the database is not updated.
+ * If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded.
+ *
+ * If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first
+ *
+ * @param string $key config key
+ * @param string $value config value
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueString(string $key, string $value, bool $lazy = false, bool $sensitive = false): bool;
+
+ /**
+ * Store a config key and its value in database
+ *
+ * When handling huge value around and/or above 2,147,483,647, a debug log will be generated
+ * on 64bits system, as php int type reach its limit (and throw an exception) on 32bits when using huge numbers.
+ *
+ * When using huge numbers, it is advised to use {@see \OCP\Util::numericToNumber()} and {@see setValueString()}
+ *
+ * If config key is already known with the exact same config value, the database is not updated.
+ * If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded.
+ *
+ * If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first
+ *
+ * @param string $key config key
+ * @param int $value config value
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueInt(string $key, int $value, bool $lazy = false, bool $sensitive = false): bool;
+
+ /**
+ * Store a config key and its value in database.
+ *
+ * If config key is already known with the exact same config value, the database is not updated.
+ * If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded.
+ *
+ * If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first
+ *
+ * @param string $key config key
+ * @param float $value config value
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueFloat(string $key, float $value, bool $lazy = false, bool $sensitive = false): bool;
+
+ /**
+ * Store a config key and its value in database
+ *
+ * If config key is already known with the exact same config value, the database is not updated.
+ * If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded.
+ *
+ * If config value was previously stored as lazy loaded, status cannot be altered without using {@see deleteKey()} first
+ *
+ * @param string $key config key
+ * @param bool $value config value
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueBool(string $key, bool $value, bool $lazy = false): bool;
+
+ /**
+ * Store a config key and its value in database
+ *
+ * If config key is already known with the exact same config value, the database is not updated.
+ * If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded.
+ *
+ * If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first
+ *
+ * @param string $key config key
+ * @param array $value config value
+ * @param bool $sensitive if TRUE value will be hidden when listing config values.
+ * @param bool $lazy set config as lazy loaded
+ *
+ * @return bool TRUE if value was different, therefor updated in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function setAppValueArray(string $key, array $value, bool $lazy = false, bool $sensitive = false): bool;
+
+ /**
* 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
+ * @deprecated 29.0.0 use {@see getAppValueString()}
*/
public function getAppValue(string $key, string $default = ''): string;
/**
+ * Get config value assigned to a config key.
+ * If config key is not found in database, default value is returned.
+ * If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE.
+ *
+ * @param string $key config key
+ * @param string $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return string stored config value or $default if not set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueString(string $key, string $default = '', bool $lazy = false): string;
+
+ /**
+ * Get config value assigned to a config key.
+ * If config key is not found in database, default value is returned.
+ * If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE.
+ *
+ * @param string $key config key
+ * @param int $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return int stored config value or $default if not set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueInt(string $key, int $default = 0, bool $lazy = false): int;
+
+ /**
+ * Get config value assigned to a config key.
+ * If config key is not found in database, default value is returned.
+ * If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE.
+ *
+ * @param string $key config key
+ * @param float $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return float stored config value or $default if not set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueFloat(string $key, float $default = 0, bool $lazy = false): float;
+
+ /**
+ * Get config value assigned to a config key.
+ * If config key is not found in database, default value is returned.
+ * If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE.
+ *
+ * @param string $key config key
+ * @param bool $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return bool stored config value or $default if not set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueBool(string $key, bool $default = false, bool $lazy = false): bool;
+
+ /**
+ * Get config value assigned to a config key.
+ * If config key is not found in database, default value is returned.
+ * If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE.
+ *
+ * @param string $key config key
+ * @param array $default default value
+ * @param bool $lazy search within lazy loaded config
+ *
+ * @return array stored config value or $default if not set in database
+ * @since 29.0.0
+ * @see \OCP\IAppConfig for explanation about lazy loading
+ */
+ public function getAppValueArray(string $key, array $default = [], bool $lazy = false): array;
+
+ /**
* Delete an app wide defined value
*
* @param string $key the key of the value, under which it was saved