aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework/Services/AppConfig.php
blob: 423a9eb5814ea41c193954b901eb9d2ebef06d2b (plain)
1
2
3
4
5
6
7
8
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?php

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-only
 */
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal Nextcloud classes

namespace OCP\Files;

/**
 * Class FileNameTooLongException
 *
 * @since 8.1.0
 */
class FileNameTooLongException extends InvalidPathException {
}
/a> 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
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 {
	public function __construct(
		private IConfig $config,
		/** @var \OC\AppConfig */
		private \OCP\IAppConfig $appConfig,
		private string $appName,
	) {
	}

	/**
	 * @inheritDoc
	 *
	 * @return string[] list of stored config keys
	 * @since 20.0.0
	 */
	public function getAppKeys(): array {
		return $this->appConfig->getKeys($this->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);
	}

	/**
	 * @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|int|float|bool|array> [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 {
		/** @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 {
		/** @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->appConfig->deleteKey($this->appName, $key);
	}

	/**
	 * @inheritDoc
	 *
	 * @since 20.0.0
	 */
	public function deleteAppValues(): void {
		$this->appConfig->deleteApp($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 {
		$this->config->deleteUserValue($userId, $this->appName, $key);
	}
}