diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2025-07-16 15:14:18 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2025-07-17 19:50:46 -0100 |
commit | 07bc32692a4a1d0b215769179074d3aab7594845 (patch) | |
tree | 9afdb58fab5b790796c6e8981873b4f1e55b5b7f | |
parent | 6b29fad7f88451ff4199bc630840c1596f5135cf (diff) | |
download | nextcloud-server-feat/lexicon/moving-out-from-unstable.tar.gz nextcloud-server-feat/lexicon/moving-out-from-unstable.zip |
feat(lexicon): marking unstable as @deprecatedfeat/lexicon/moving-out-from-unstable
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | core/AppInfo/ConfigLexicon.php | 18 | ||||
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 9 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 9 | ||||
-rw-r--r-- | lib/unstable/Config/Exceptions/IncorrectTypeException.php | 19 | ||||
-rw-r--r-- | lib/unstable/Config/Exceptions/TypeConflictException.php | 19 | ||||
-rw-r--r-- | lib/unstable/Config/Exceptions/UnknownKeyException.php | 20 | ||||
-rw-r--r-- | lib/unstable/Config/IUserConfig.php | 831 | ||||
-rw-r--r-- | lib/unstable/Config/Lexicon/ConfigLexiconEntry.php | 297 | ||||
-rw-r--r-- | lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php | 48 | ||||
-rw-r--r-- | lib/unstable/Config/Lexicon/IConfigLexicon.php | 55 | ||||
-rw-r--r-- | lib/unstable/Config/Lexicon/Preset.php | 75 | ||||
-rw-r--r-- | lib/unstable/Config/ValueType.php | 143 |
12 files changed, 1534 insertions, 9 deletions
diff --git a/core/AppInfo/ConfigLexicon.php b/core/AppInfo/ConfigLexicon.php index cc7fd1a3b09..5dad229267d 100644 --- a/core/AppInfo/ConfigLexicon.php +++ b/core/AppInfo/ConfigLexicon.php @@ -8,31 +8,31 @@ declare(strict_types=1); namespace OC\Core\AppInfo; -use NCU\Config\Lexicon\ConfigLexiconEntry; -use NCU\Config\Lexicon\ConfigLexiconStrictness; -use NCU\Config\Lexicon\IConfigLexicon; -use NCU\Config\ValueType; +use OCP\Config\Lexicon\Entry; +use OCP\Config\Lexicon\ILexicon; +use OCP\Config\Lexicon\Strictness; +use OCP\Config\ValueType; /** * Config Lexicon for core. * * Please Add & Manage your Config Keys in that file and keep the Lexicon up to date! */ -class ConfigLexicon implements IConfigLexicon { +class ConfigLexicon implements ILexicon { public const SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES = 'shareapi_allow_federation_on_public_shares'; - public function getStrictness(): ConfigLexiconStrictness { - return ConfigLexiconStrictness::IGNORE; + public function getStrictness(): Strictness { + return Strictness::IGNORE; } public function getAppConfigs(): array { return [ - new ConfigLexiconEntry( + new Entry( key: self::SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES, type: ValueType::BOOL, - lazy: true, defaultRaw: true, definition: 'adds share permission to public shares to allow adding them to your Nextcloud (federation)', + lazy: true, ), ]; } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8586e1e9c31..65c1a299dec 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -7,6 +7,15 @@ $baseDir = dirname(dirname($vendorDir)); return array( 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', + 'NCU\\Config\\Exceptions\\IncorrectTypeException' => $baseDir . '/lib/unstable/Config/Exceptions/IncorrectTypeException.php', + 'NCU\\Config\\Exceptions\\TypeConflictException' => $baseDir . '/lib/unstable/Config/Exceptions/TypeConflictException.php', + 'NCU\\Config\\Exceptions\\UnknownKeyException' => $baseDir . '/lib/unstable/Config/Exceptions/UnknownKeyException.php', + 'NCU\\Config\\IUserConfig' => $baseDir . '/lib/unstable/Config/IUserConfig.php', + 'NCU\\Config\\Lexicon\\ConfigLexiconEntry' => $baseDir . '/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php', + 'NCU\\Config\\Lexicon\\ConfigLexiconStrictness' => $baseDir . '/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php', + 'NCU\\Config\\Lexicon\\IConfigLexicon' => $baseDir . '/lib/unstable/Config/Lexicon/IConfigLexicon.php', + 'NCU\\Config\\Lexicon\\Preset' => $baseDir . '/lib/unstable/Config/Lexicon/Preset.php', + 'NCU\\Config\\ValueType' => $baseDir . '/lib/unstable/Config/ValueType.php', 'NCU\\Federation\\ISignedCloudFederationProvider' => $baseDir . '/lib/unstable/Federation/ISignedCloudFederationProvider.php', 'NCU\\Security\\Signature\\Enum\\DigestAlgorithm' => $baseDir . '/lib/unstable/Security/Signature/Enum/DigestAlgorithm.php', 'NCU\\Security\\Signature\\Enum\\SignatoryStatus' => $baseDir . '/lib/unstable/Security/Signature/Enum/SignatoryStatus.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d9362634b63..909ac3599f5 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -48,6 +48,15 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 public static $classMap = array ( 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'NCU\\Config\\Exceptions\\IncorrectTypeException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/IncorrectTypeException.php', + 'NCU\\Config\\Exceptions\\TypeConflictException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/TypeConflictException.php', + 'NCU\\Config\\Exceptions\\UnknownKeyException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/UnknownKeyException.php', + 'NCU\\Config\\IUserConfig' => __DIR__ . '/../../..' . '/lib/unstable/Config/IUserConfig.php', + 'NCU\\Config\\Lexicon\\ConfigLexiconEntry' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php', + 'NCU\\Config\\Lexicon\\ConfigLexiconStrictness' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php', + 'NCU\\Config\\Lexicon\\IConfigLexicon' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/IConfigLexicon.php', + 'NCU\\Config\\Lexicon\\Preset' => __DIR__ . '/../../..' . '/lib/unstable/Config/Lexicon/Preset.php', + 'NCU\\Config\\ValueType' => __DIR__ . '/../../..' . '/lib/unstable/Config/ValueType.php', 'NCU\\Federation\\ISignedCloudFederationProvider' => __DIR__ . '/../../..' . '/lib/unstable/Federation/ISignedCloudFederationProvider.php', 'NCU\\Security\\Signature\\Enum\\DigestAlgorithm' => __DIR__ . '/../../..' . '/lib/unstable/Security/Signature/Enum/DigestAlgorithm.php', 'NCU\\Security\\Signature\\Enum\\SignatoryStatus' => __DIR__ . '/../../..' . '/lib/unstable/Security/Signature/Enum/SignatoryStatus.php', diff --git a/lib/unstable/Config/Exceptions/IncorrectTypeException.php b/lib/unstable/Config/Exceptions/IncorrectTypeException.php new file mode 100644 index 00000000000..b21e1dc1c14 --- /dev/null +++ b/lib/unstable/Config/Exceptions/IncorrectTypeException.php @@ -0,0 +1,19 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config\Exceptions; + +use Exception; + +/** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Exceptions\IncorrectTypeException + * @see \OCP\Config\Exceptions\IncorrectTypeException + */ +class IncorrectTypeException extends Exception { +} diff --git a/lib/unstable/Config/Exceptions/TypeConflictException.php b/lib/unstable/Config/Exceptions/TypeConflictException.php new file mode 100644 index 00000000000..f97e9bca9af --- /dev/null +++ b/lib/unstable/Config/Exceptions/TypeConflictException.php @@ -0,0 +1,19 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config\Exceptions; + +use Exception; + +/** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Exceptions\TypeConflictException + * @see \OCP\Config\Exceptions\TypeConflictException + */ +class TypeConflictException extends Exception { +} diff --git a/lib/unstable/Config/Exceptions/UnknownKeyException.php b/lib/unstable/Config/Exceptions/UnknownKeyException.php new file mode 100644 index 00000000000..9c2d0bbf73b --- /dev/null +++ b/lib/unstable/Config/Exceptions/UnknownKeyException.php @@ -0,0 +1,20 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config\Exceptions; + +use Exception; + +/** + * @experimental 31.0.0 + * @deprecated + * @deprecated use \OCP\Config\Exceptions\UnknownKeyException + * @see \OCP\Config\Exceptions\UnknownKeyException + */ +class UnknownKeyException extends Exception { +} diff --git a/lib/unstable/Config/IUserConfig.php b/lib/unstable/Config/IUserConfig.php new file mode 100644 index 00000000000..52bc60289b8 --- /dev/null +++ b/lib/unstable/Config/IUserConfig.php @@ -0,0 +1,831 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config; + +use Generator; +use NCU\Config\Exceptions\IncorrectTypeException; +use NCU\Config\Exceptions\UnknownKeyException; + +/** + * This class provides an easy way for apps to store user config in the + * database. + * Supports **lazy loading** + * + * ### What is lazy loading ? + * In order to avoid loading useless user config into memory for each request, + * only non-lazy values are now loaded. + * + * Once a value that is lazy is requested, all lazy values will be loaded. + * + * Similarly, some methods from this class are marked with a warning about ignoring + * lazy loading. Use them wisely and only on parts of the code that are called + * during specific requests or actions to avoid loading the lazy values all the time. + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ +interface IUserConfig { + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public const FLAG_SENSITIVE = 1; // value is sensitive + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public const FLAG_INDEXED = 2; // value should be indexed + + /** + * Get list of all userIds with config stored in database. + * If $appId is specified, will only limit the search to this value + * + * **WARNING:** ignore any cache and get data directly from database. + * + * @param string $appId optional id of app + * + * @return list<string> list of userIds + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getUserIds(string $appId = ''): array; + + /** + * Get list of all apps that have at least one config + * value related to $userId stored in database + * + * **WARNING:** ignore lazy filtering, all user config are loaded from database + * + * @param string $userId id of the user + * + * @return list<string> list of app ids + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getApps(string $userId): array; + + /** + * Returns all keys stored in database, related to user+app. + * Please note that the values are not returned. + * + * **WARNING:** ignore lazy filtering, all user config are loaded from database + * + * @param string $userId id of the user + * @param string $app id of the app + * + * @return list<string> list of stored config keys + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getKeys(string $userId, string $app): array; + + /** + * Check if a key exists in the list of stored config values. + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool $lazy search within lazy loaded config + * + * @return bool TRUE if key exists + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function hasKey(string $userId, string $app, string $key, ?bool $lazy = false): bool; + + /** + * best way to see if a value is set as sensitive (not displayed in report) + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool|null $lazy search within lazy loaded config + * + * @return bool TRUE if value is sensitive + * @throws UnknownKeyException if config key is not known + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function isSensitive(string $userId, string $app, string $key, ?bool $lazy = false): bool; + + /** + * best way to see if a value is set as indexed (so it can be search) + * + * @see self::searchUsersByValueString() + * @see self::searchUsersByValueInt() + * @see self::searchUsersByValueBool() + * @see self::searchUsersByValues() + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool|null $lazy search within lazy loaded config + * + * @return bool TRUE if value is sensitive + * @throws UnknownKeyException if config key is not known + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function isIndexed(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @param string $key config key + * + * @return bool TRUE if config is lazy loaded + * @throws UnknownKeyException if config key is not known + * @see IUserConfig for details about lazy loading + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function isLazy(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @param string $prefix config keys prefix to search, can be empty. + * @param bool $filtered filter sensitive config values + * + * @return array<string, string|int|float|bool|array> [key => value] + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getValues(string $userId, string $app, string $prefix = '', bool $filtered = false): array; + + /** + * List all config values of a user. + * 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 $userId id of the user + * @param bool $filtered filter sensitive config values + * + * @return array<string, string|int|float|bool|array> [key => value] + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getAllValues(string $userId, bool $filtered = false): array; + + /** + * List all apps storing a specific config key and its stored value. + * Returns an array with appId as key, stored value as value. + * + * @param string $userId id of the user + * @param string $key config key + * @param bool $lazy search within lazy loaded config + * @param ValueType|null $typedAs enforce type for the returned values + * + * @return array<string, string|int|float|bool|array> [appId => value] + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * @psalm-suppress DeprecatedClass + */ + public function getValuesByApps(string $userId, string $key, bool $lazy = false, ?ValueType $typedAs = null): array; + + /** + * List all users storing a specific config key and its stored value. + * Returns an array with userId as key, stored value as value. + * + * **WARNING:** no caching, generate a fresh request + * + * @param string $app id of the app + * @param string $key config key + * @param ValueType|null $typedAs enforce type for the returned values + * @param array|null $userIds limit the search to a list of user ids + * + * @return array<string, string|int|float|bool|array> [userId => value] + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * @psalm-suppress DeprecatedClass + */ + public function getValuesByUsers(string $app, string $key, ?ValueType $typedAs = null, ?array $userIds = null): array; + + /** + * List all users storing a specific config key/value pair. + * Returns a list of user ids. + * + * **WARNING:** no caching, generate a fresh request + * + * @param string $app id of the app + * @param string $key config key + * @param string $value config value + * @param bool $caseInsensitive non-case-sensitive search, only works if $value is a string + * + * @return Generator<string> + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function searchUsersByValueString(string $app, string $key, string $value, bool $caseInsensitive = false): Generator; + + /** + * List all users storing a specific config key/value pair. + * Returns a list of user ids. + * + * **WARNING:** no caching, generate a fresh request + * + * @param string $app id of the app + * @param string $key config key + * @param int $value config value + * + * @return Generator<string> + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function searchUsersByValueInt(string $app, string $key, int $value): Generator; + + /** + * List all users storing a specific config key/value pair. + * Returns a list of user ids. + * + * **WARNING:** no caching, generate a fresh request + * + * @param string $app id of the app + * @param string $key config key + * @param array $values list of possible config values + * + * @return Generator<string> + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function searchUsersByValues(string $app, string $key, array $values): Generator; + + /** + * List all users storing a specific config key/value pair. + * Returns a list of user ids. + * + * **WARNING:** no caching, generate a fresh request + * + * @param string $app id of the app + * @param string $key config key + * @param bool $value config value + * + * @return Generator<string> + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function searchUsersByValueBool(string $app, string $key, bool $value): Generator; + + /** + * Get user config 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see getValueInt() + * @see getValueFloat() + * @see getValueBool() + * @see getValueArray() + */ + public function getValueString(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see getValueString() + * @see getValueFloat() + * @see getValueBool() + * @see getValueArray() + */ + public function getValueInt(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see getValueString() + * @see getValueInt() + * @see getValueBool() + * @see getValueArray() + */ + public function getValueFloat(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserPrefences for explanation about lazy loading + * @see getValueString() + * @see getValueInt() + * @see getValueFloat() + * @see getValueArray() + */ + public function getValueBool(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see getValueString() + * @see getValueInt() + * @see getValueFloat() + * @see getValueBool() + */ + public function getValueArray(string $userId, string $app, string $key, array $default = [], bool $lazy = false): array; + + /** + * returns the type of config value + * + * **WARNING:** ignore lazy filtering, all config values are loaded from database + * unless lazy is set to false + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool|null $lazy + * + * @return ValueType type of the value + * @throws UnknownKeyException if config key is not known + * @throws IncorrectTypeException if config value type is not known + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * @psalm-suppress DeprecatedClass + */ + public function getValueType(string $userId, string $app, string $key, ?bool $lazy = null): ValueType; + + /** + * returns a bitflag related to config value + * + * **WARNING:** ignore lazy filtering, all config values are loaded from database + * unless lazy is set to false + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool $lazy lazy loading + * + * @return int a bitflag in relation to the config value + * @throws UnknownKeyException if config key is not known + * @throws IncorrectTypeException if config value type is not known + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getValueFlags(string $userId, string $app, string $key, bool $lazy = false): int; + + /** + * 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see setValueInt() + * @see setValueFloat() + * @see setValueBool() + * @see setValueArray() + */ + public function setValueString(string $userId, string $app, string $key, string $value, bool $lazy = false, int $flags = 0): 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see setValueString() + * @see setValueFloat() + * @see setValueBool() + * @see setValueArray() + */ + public function setValueInt(string $userId, string $app, string $key, int $value, bool $lazy = false, int $flags = 0): 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see setValueString() + * @see setValueInt() + * @see setValueBool() + * @see setValueArray() + */ + public function setValueFloat(string $userId, string $app, string $key, float $value, bool $lazy = false, int $flags = 0): 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see setValueString() + * @see setValueInt() + * @see setValueFloat() + * @see setValueArray() + */ + public function setValueBool(string $userId, string $app, 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 $userId id of the user + * @param string $app id of the app + * @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 + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + * + * @see IUserConfig for explanation about lazy loading + * @see setValueString() + * @see setValueInt() + * @see setValueFloat() + * @see setValueBool() + */ + public function setValueArray(string $userId, string $app, string $key, array $value, bool $lazy = false, int $flags = 0): bool; + + /** + * switch sensitive status of a config value + * + * **WARNING:** ignore lazy filtering, all config values are loaded from database + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool $sensitive TRUE to set as sensitive, FALSE to unset + * + * @return bool TRUE if database update were necessary + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateSensitive(string $userId, string $app, string $key, bool $sensitive): bool; + + /** + * switch sensitive loading status of a config key for all users + * + * **Warning:** heavy on resources, MUST only be used on occ command or migrations + * + * @param string $app id of the app + * @param string $key config key + * @param bool $sensitive TRUE to set as sensitive, FALSE to unset + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateGlobalSensitive(string $app, string $key, bool $sensitive): void; + + + /** + * switch indexed status of a config value + * + * **WARNING:** ignore lazy filtering, all config values are loaded from database + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool $indexed TRUE to set as indexed, FALSE to unset + * + * @return bool TRUE if database update were necessary + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateIndexed(string $userId, string $app, string $key, bool $indexed): bool; + + /** + * switch sensitive loading status of a config key for all users + * + * **Warning:** heavy on resources, MUST only be used on occ command or migrations + * + * @param string $app id of the app + * @param string $key config key + * @param bool $indexed TRUE to set as indexed, FALSE to unset + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateGlobalIndexed(string $app, string $key, bool $indexed): void; + + /** + * switch lazy loading status of a config value + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * @param bool $lazy TRUE to set as lazy loaded, FALSE to unset + * + * @return bool TRUE if database update was necessary + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateLazy(string $userId, string $app, string $key, bool $lazy): bool; + + /** + * switch lazy loading status of a config key for all users + * + * **Warning:** heavy on resources, MUST only be used on occ command or migrations + * + * @param string $app id of the app + * @param string $key config key + * @param bool $lazy TRUE to set as lazy loaded, FALSE to unset + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function updateGlobalLazy(string $app, string $key, bool $lazy): void; + + /** + * returns an array contains details about a config value + * + * ``` + * [ + * "app" => "myapp", + * "key" => "mykey", + * "value" => "its_value", + * "lazy" => false, + * "type" => 4, + * "typeString" => "string", + * 'sensitive' => true + * ] + * ``` + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * + * @return array + * @throws UnknownKeyException if config key is not known in database + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function getDetails(string $userId, string $app, string $key): array; + + /** + * Delete single config key from database. + * + * @param string $userId id of the user + * @param string $app id of the app + * @param string $key config key + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function deleteUserConfig(string $userId, string $app, string $key): void; + + /** + * Delete config values from all users linked to a specific config keys + * + * @param string $app id of the app + * @param string $key config key + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function deleteKey(string $app, string $key): void; + + /** + * delete all config keys linked to an app + * + * @param string $app id of the app + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function deleteApp(string $app): void; + + /** + * delete all config keys linked to a user + * + * @param string $userId id of the user + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function deleteAllUserConfig(string $userId): void; + + /** + * Clear the cache for a single user + * + * The cache will be rebuilt only the next time a user config is requested. + * + * @param string $userId id of the user + * @param bool $reload set to TRUE to refill cache instantly after clearing it + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function clearCache(string $userId, bool $reload = false): void; + + /** + * Clear the cache for all users. + * The cache will be rebuilt only the next time a user config is requested. + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\IUserConfig + * @see \OCP\Config\IUserConfig + */ + public function clearCacheAll(): void; +} diff --git a/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php new file mode 100644 index 00000000000..34da89f75b4 --- /dev/null +++ b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php @@ -0,0 +1,297 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config\Lexicon; + +use Closure; +use NCU\Config\ValueType; + +/** + * Model that represent config values within an app config lexicon. + * + * @see IConfigLexicon + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress DeprecatedClass + */ +class ConfigLexiconEntry { + /** + * @experimental 32.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public const RENAME_INVERT_BOOLEAN = 1; + + private string $definition = ''; + private ?string $default = null; + + /** + * @param string $key config key, can only contain alphanumerical chars and -._ + * @param ValueType $type type of config value + * @param string $definition optional description of config key available when using occ command + * @param bool $lazy set config value as lazy + * @param int $flags set flags + * @param string|null $rename previous config key to migrate config value from + * @param bool $deprecated set config key as deprecated + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress PossiblyInvalidCast + * @psalm-suppress RiskyCast + */ + public function __construct( + private readonly string $key, + private readonly ValueType $type, + private null|string|int|float|bool|array|Closure $defaultRaw = null, + string $definition = '', + private readonly bool $lazy = false, + private readonly int $flags = 0, + private readonly bool $deprecated = false, + private readonly ?string $rename = null, + private readonly int $options = 0, + ) { + // key can only contain alphanumeric chars and underscore "_" + if (preg_match('/[^[:alnum:]_]/', $key)) { + throw new \Exception('invalid config key'); + } + + /** @psalm-suppress UndefinedClass */ + if (\OC::$CLI) { // only store definition if ran from CLI + $this->definition = $definition; + } + } + + /** + * returns the config key + * + * @return string config key + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function getKey(): string { + return $this->key; + } + + /** + * get expected type for config value + * + * @return ValueType + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress DeprecatedClass + */ + public function getValueType(): ValueType { + return $this->type; + } + + /** + * @param string $default + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + private function convertFromString(string $default): string { + return $default; + } + + /** + * @param int $default + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + private function convertFromInt(int $default): string { + return (string)$default; + } + + /** + * @param float $default + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + private function convertFromFloat(float $default): string { + return (string)$default; + } + + /** + * @param bool $default + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + private function convertFromBool(bool $default): string { + return ($default) ? '1' : '0'; + } + + /** + * @param array $default + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + private function convertFromArray(array $default): string { + return json_encode($default); + } + + /** + * returns default value + * + * @return string|null NULL if no default is set + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress DeprecatedClass + * @psalm-suppress DeprecatedMethod + */ + public function getDefault(Preset $preset): ?string { + if ($this->default !== null) { + return $this->default; + } + + if ($this->defaultRaw === null) { + return null; + } + + if ($this->defaultRaw instanceof Closure) { + /** @psalm-suppress MixedAssignment we expect closure to returns string|int|float|bool|array */ + $this->defaultRaw = ($this->defaultRaw)($preset); + } + + /** @psalm-suppress MixedArgument closure should be managed previously */ + $this->default = $this->convertToString($this->defaultRaw); + + return $this->default; + } + + /** + * convert $entry into string, based on the expected type for config value + * + * @param string|int|float|bool|array $entry + * + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress PossiblyInvalidCast arrays are managed pre-cast + * @psalm-suppress RiskyCast + * @psalm-suppress DeprecatedClass + * @psalm-suppress DeprecatedMethod + * @psalm-suppress DeprecatedConstant + */ + public function convertToString(string|int|float|bool|array $entry): string { + // in case $default is array but is not expected to be an array... + if ($this->getValueType() !== ValueType::ARRAY && is_array($entry)) { + $entry = json_encode($entry, JSON_THROW_ON_ERROR); + } + + return match ($this->getValueType()) { + ValueType::MIXED => (string)$entry, + ValueType::STRING => $this->convertFromString((string)$entry), + ValueType::INT => $this->convertFromInt((int)$entry), + ValueType::FLOAT => $this->convertFromFloat((float)$entry), + ValueType::BOOL => $this->convertFromBool((bool)$entry), + ValueType::ARRAY => $this->convertFromArray((array)$entry) + }; + } + + /** + * returns definition + * + * @return string + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function getDefinition(): string { + return $this->definition; + } + + /** + * returns if config key is set as lazy + * + * @see IAppConfig for details on lazy config values + * @return bool TRUE if config value is lazy + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function isLazy(): bool { + return $this->lazy; + } + + /** + * returns flags + * + * @see IAppConfig for details on sensitive config values + * @return int bitflag about the config value + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function getFlags(): int { + return $this->flags; + } + + /** + * @param int $flag + * + * @return bool TRUE is config value bitflag contains $flag + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @psalm-suppress DeprecatedMethod + */ + public function isFlagged(int $flag): bool { + return (($flag & $this->getFlags()) === $flag); + } + + /** + * should be called/used only during migration/upgrade. + * link to an old config key. + * + * @return string|null not NULL if value can be imported from a previous key + * @experimental 32.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function getRename(): ?string { + return $this->rename; + } + + /** + * @experimental 32.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + * @return bool TRUE if $option was set during the creation of the entry. + */ + public function hasOption(int $option): bool { + return (($option & $this->options) !== 0); + } + + /** + * returns if config key is set as deprecated + * + * @return bool TRUE if config si deprecated + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Entry + * @see \OCP\Config\Lexicon\Entry + */ + public function isDeprecated(): bool { + return $this->deprecated; + } +} diff --git a/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php b/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php new file mode 100644 index 00000000000..5da6fca8362 --- /dev/null +++ b/lib/unstable/Config/Lexicon/ConfigLexiconStrictness.php @@ -0,0 +1,48 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +namespace NCU\Config\Lexicon; + +/** + * Strictness regarding using not-listed config keys + * + * - **ConfigLexiconStrictness::IGNORE** - fully ignore + * - **ConfigLexiconStrictness::NOTICE** - ignore and report + * - **ConfigLexiconStrictness::WARNING** - silently block (returns $default) and report + * - **ConfigLexiconStrictness::EXCEPTION** - block (throws exception) and report + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Strictness + * @see \OCP\Config\Lexicon\Strictness + */ +enum ConfigLexiconStrictness { + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Strictness + * @see \OCP\Config\Lexicon\Strictness + */ + case IGNORE; // fully ignore + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Strictness + * @see \OCP\Config\Lexicon\Strictness + */ + case NOTICE; // ignore and report + /** + * @deprecated use \OCP\Config\Lexicon\Strictness + * @see \OCP\Config\Lexicon\Strictness + * @experimental 31.0.0 + */ + case WARNING; // silently block (returns $default) and report + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\Strictness + * @see \OCP\Config\Lexicon\Strictness + */ + case EXCEPTION; // block (throws exception) and report +} diff --git a/lib/unstable/Config/Lexicon/IConfigLexicon.php b/lib/unstable/Config/Lexicon/IConfigLexicon.php new file mode 100644 index 00000000000..969655d068a --- /dev/null +++ b/lib/unstable/Config/Lexicon/IConfigLexicon.php @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +namespace NCU\Config\Lexicon; + +/** + * This interface needs to be implemented if you want to define a config lexicon for your application + * The config lexicon is used to avoid conflicts and problems when storing/retrieving config values + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\ILexicon + * @see \OCP\Config\Lexicon\ILexicon + */ +interface IConfigLexicon { + + /** + * Define the expected behavior when using config + * keys not set within your application config lexicon. + * + * @return ConfigLexiconStrictness + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\ILexicon + * @see \OCP\Config\Lexicon\ILexicon + * @psalm-suppress DeprecatedClass + * + */ + public function getStrictness(): ConfigLexiconStrictness; + + /** + * define the list of entries of your application config lexicon, related to AppConfig. + * + * @return ConfigLexiconEntry[] + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\ILexicon + * @see \OCP\Config\Lexicon\ILexicon + * @psalm-suppress DeprecatedClass + */ + public function getAppConfigs(): array; + + /** + * define the list of entries of your application config lexicon, related to UserPreferences. + * + * @return ConfigLexiconEntry[] + * @experimental 31.0.0 + * @deprecated use \OCP\Config\Lexicon\ILexicon + * @see \OCP\Config\Lexicon\ILexicon + * @psalm-suppress DeprecatedClass + */ + public function getUserConfigs(): array; +} diff --git a/lib/unstable/Config/Lexicon/Preset.php b/lib/unstable/Config/Lexicon/Preset.php new file mode 100644 index 00000000000..fb50756c535 --- /dev/null +++ b/lib/unstable/Config/Lexicon/Preset.php @@ -0,0 +1,75 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +namespace NCU\Config\Lexicon; + +/** + * list of preset to handle the default behavior of the instance + * + * @see ConfigLexiconEntry::preset + * + * - **Preset::LARGE** - Large size organisation (> 50k accounts) + * - **Preset::MEDIUM** - Medium size organisation (> 100 accounts) + * - **Preset::SMALL** - Small size organisation (< 100 accounts) + * - **Preset::SHARED** - Shared hosting + * - **Preset::EDUCATION** - School/University + * - **Preset::CLUB** - Club/Association + * - **Preset::FAMILY** - Family + * - **Preset::PRIVATE** - Private + * + * @experimental 32.0.0 + * @deprecated use \OCP\Config\Lexicon\Preset + * @see \OCP\Config\Lexicon\Preset + */ +enum Preset: int { + /** + * @experimental 32.0.0 + * @deprecated + */ + case LARGE = 8; + /** + * @experimental 32.0.0 + * @deprecated + */ + case MEDIUM = 7; + /** + * @experimental 32.0.0 + * @deprecated + */ + case SMALL = 6; + /** + * @experimental 32.0.0 + * @deprecated + */ + case SHARED = 5; + /** + * @experimental 32.0.0 + * @deprecated + */ + case EDUCATION = 4; + /** + * @experimental 32.0.0 + * @deprecated + */ + case CLUB = 3; + /** + * @experimental 32.0.0 + * @deprecated + */ + case FAMILY = 2; + /** + * @experimental 32.0.0 + * @deprecated + */ + case PRIVATE = 1; + /** + * @experimental 32.0.0 + * @deprecated + */ + case NONE = 0; +} diff --git a/lib/unstable/Config/ValueType.php b/lib/unstable/Config/ValueType.php new file mode 100644 index 00000000000..beca7ff34bc --- /dev/null +++ b/lib/unstable/Config/ValueType.php @@ -0,0 +1,143 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace NCU\Config; + +use NCU\Config\Exceptions\IncorrectTypeException; +use OCP\IAppConfig; +use UnhandledMatchError; + +/** + * Listing of available value type for typed config value + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ +enum ValueType: int { + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case MIXED = 0; + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case STRING = 1; + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case INT = 2; + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case FLOAT = 3; + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case BOOL = 4; + /** + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + */ + case ARRAY = 5; + + /** + * get ValueType from string + * + * @param string $definition + * + * @return self + * @throws IncorrectTypeException + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + * @psalm-suppress DeprecatedConstant + * @psalm-suppress DeprecatedClass + */ + public static function fromStringDefinition(string $definition): self { + try { + return match ($definition) { + 'mixed' => self::MIXED, + 'string' => self::STRING, + 'int' => self::INT, + 'float' => self::FLOAT, + 'bool' => self::BOOL, + 'array' => self::ARRAY + }; + } catch (\UnhandledMatchError) { + throw new IncorrectTypeException('unknown string definition'); + } + } + + /** + * get string definition for current enum value + * + * @return string + * @throws IncorrectTypeException + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + * @psalm-suppress DeprecatedConstant + * @psalm-suppress DeprecatedClass + */ + public function getDefinition(): string { + try { + return match ($this) { + self::MIXED => 'mixed', + self::STRING => 'string', + self::INT => 'int', + self::FLOAT => 'float', + self::BOOL => 'bool', + self::ARRAY => 'array', + }; + } catch (UnhandledMatchError) { + throw new IncorrectTypeException('unknown type definition ' . $this->value); + } + } + + /** + * get corresponding AppConfig flag value + * + * @return int + * @throws IncorrectTypeException + * + * @experimental 31.0.0 + * @deprecated use \OCP\Config\ValueType + * @see \OCP\Config\ValueType + * @psalm-suppress DeprecatedConstant + * @psalm-suppress DeprecatedClass + */ + public function toAppConfigFlag(): int { + try { + return match ($this) { + self::MIXED => IAppConfig::VALUE_MIXED, + self::STRING => IAppConfig::VALUE_STRING, + self::INT => IAppConfig::VALUE_INT, + self::FLOAT => IAppConfig::VALUE_FLOAT, + self::BOOL => IAppConfig::VALUE_BOOL, + self::ARRAY => IAppConfig::VALUE_ARRAY, + }; + } catch (UnhandledMatchError) { + throw new IncorrectTypeException('unknown type definition ' . $this->value); + } + } + +} |