aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib/DefinitionParameter.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Lib/DefinitionParameter.php')
-rw-r--r--apps/files_external/lib/Lib/DefinitionParameter.php133
1 files changed, 78 insertions, 55 deletions
diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/apps/files_external/lib/Lib/DefinitionParameter.php
index c1108fccce7..a73dd2df967 100644
--- a/apps/files_external/lib/Lib/DefinitionParameter.php
+++ b/apps/files_external/lib/Lib/DefinitionParameter.php
@@ -1,76 +1,63 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Lib;
/**
* Parameter for an external storage definition
*/
class DefinitionParameter implements \JsonSerializable {
+ // placeholder value for password fields, when the client updates a storage configuration
+ // placeholder values are ignored and the field is left unmodified
+ public const UNMODIFIED_PLACEHOLDER = '__unmodified__';
/** Value constants */
- const VALUE_TEXT = 0;
- const VALUE_BOOLEAN = 1;
- const VALUE_PASSWORD = 2;
- const VALUE_HIDDEN = 3;
+ public const VALUE_TEXT = 0;
+ public const VALUE_BOOLEAN = 1;
+ public const VALUE_PASSWORD = 2;
/** Flag constants */
- const FLAG_NONE = 0;
- const FLAG_OPTIONAL = 1;
- const FLAG_USER_PROVIDED = 2;
+ public const FLAG_NONE = 0;
+ public const FLAG_OPTIONAL = 1;
+ public const FLAG_USER_PROVIDED = 2;
+ public const FLAG_HIDDEN = 4;
- /** @var string name of parameter */
- private $name;
-
- /** @var string human-readable parameter text */
- private $text;
+ /** @var string human-readable parameter tooltip */
+ private string $tooltip = '';
/** @var int value type, see self::VALUE_* constants */
- private $type = self::VALUE_TEXT;
+ private int $type = self::VALUE_TEXT;
/** @var int flags, see self::FLAG_* constants */
- private $flags = self::FLAG_NONE;
+ private int $flags = self::FLAG_NONE;
/**
- * @param string $name
- * @param string $text
+ * @param string $name parameter name
+ * @param string $text parameter description
+ * @param mixed $defaultValue default value
*/
- public function __construct($name, $text) {
- $this->name = $name;
- $this->text = $text;
+ public function __construct(
+ private string $name,
+ private string $text,
+ private $defaultValue = null,
+ ) {
}
/**
* @return string
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
/**
* @return string
*/
- public function getText() {
+ public function getText(): string {
return $this->text;
}
@@ -79,7 +66,7 @@ class DefinitionParameter implements \JsonSerializable {
*
* @return int
*/
- public function getType() {
+ public function getType(): int {
return $this->type;
}
@@ -89,15 +76,31 @@ class DefinitionParameter implements \JsonSerializable {
* @param int $type
* @return self
*/
- public function setType($type) {
+ public function setType(int $type) {
$this->type = $type;
return $this;
}
/**
+ * @return mixed default value
+ */
+ public function getDefaultValue() {
+ return $this->defaultValue;
+ }
+
+ /**
+ * @param mixed $defaultValue default value
+ * @return self
+ */
+ public function setDefaultValue($defaultValue) {
+ $this->defaultValue = $defaultValue;
+ return $this;
+ }
+
+ /**
* @return string
*/
- public function getTypeName() {
+ public function getTypeName(): string {
switch ($this->type) {
case self::VALUE_BOOLEAN:
return 'boolean';
@@ -113,7 +116,7 @@ class DefinitionParameter implements \JsonSerializable {
/**
* @return int
*/
- public function getFlags() {
+ public function getFlags(): int {
return $this->flags;
}
@@ -121,7 +124,7 @@ class DefinitionParameter implements \JsonSerializable {
* @param int $flags
* @return self
*/
- public function setFlags($flags) {
+ public function setFlags(int $flags) {
$this->flags = $flags;
return $this;
}
@@ -130,7 +133,7 @@ class DefinitionParameter implements \JsonSerializable {
* @param int $flag
* @return self
*/
- public function setFlag($flag) {
+ public function setFlag(int $flag) {
$this->flags |= $flag;
return $this;
}
@@ -139,24 +142,44 @@ class DefinitionParameter implements \JsonSerializable {
* @param int $flag
* @return bool
*/
- public function isFlagSet($flag) {
+ public function isFlagSet(int $flag): bool {
return (bool)($this->flags & $flag);
}
/**
- * Serialize into JSON for client-side JS
- *
* @return string
*/
- public function jsonSerialize() {
- return [
+ public function getTooltip(): string {
+ return $this->tooltip;
+ }
+
+ /**
+ * @param string $tooltip
+ * @return self
+ */
+ public function setTooltip(string $tooltip) {
+ $this->tooltip = $tooltip;
+ return $this;
+ }
+
+ /**
+ * Serialize into JSON for client-side JS
+ */
+ public function jsonSerialize(): array {
+ $result = [
'value' => $this->getText(),
'flags' => $this->getFlags(),
- 'type' => $this->getType()
+ 'type' => $this->getType(),
+ 'tooltip' => $this->getTooltip(),
];
+ $defaultValue = $this->getDefaultValue();
+ if ($defaultValue) {
+ $result['defaultValue'] = $defaultValue;
+ }
+ return $result;
}
- public function isOptional() {
+ public function isOptional(): bool {
return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
}
@@ -167,7 +190,7 @@ class DefinitionParameter implements \JsonSerializable {
* @param mixed $value Value to check
* @return bool success
*/
- public function validateValue(&$value) {
+ public function validateValue(&$value): bool {
switch ($this->getType()) {
case self::VALUE_BOOLEAN:
if (!is_bool($value)) {