summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-10-17 00:55:48 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-10-17 10:58:27 +0200
commitc94f9f5e5f41b197dcbfbdc3526b8c5e6198d786 (patch)
treed06ce53b1c897dee2e0f74e42bc6cb7d416638d7 /apps/files_external
parent2d75321c2360fb20bf3705ef0b6c82ab320cc3ae (diff)
downloadnextcloud-server-c94f9f5e5f41b197dcbfbdc3526b8c5e6198d786.tar.gz
nextcloud-server-c94f9f5e5f41b197dcbfbdc3526b8c5e6198d786.zip
Add corresponding interface to trait
Since we can't specify that we want a class implementing a trait yet in PHP Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/Lib/Auth/AuthMechanism.php4
-rw-r--r--apps/files_external/lib/Lib/Backend/Backend.php4
-rw-r--r--apps/files_external/lib/Lib/FrontendDefinitionTrait.php48
-rw-r--r--apps/files_external/lib/Lib/IFrontendDefinition.php56
-rw-r--r--apps/files_external/lib/Lib/IIdentifier.php27
-rw-r--r--apps/files_external/lib/Lib/IdentifierTrait.php44
-rw-r--r--apps/files_external/lib/Lib/PriorityTrait.php9
7 files changed, 112 insertions, 80 deletions
diff --git a/apps/files_external/lib/Lib/Auth/AuthMechanism.php b/apps/files_external/lib/Lib/Auth/AuthMechanism.php
index 929068ea7ef..16354fa37fa 100644
--- a/apps/files_external/lib/Lib/Auth/AuthMechanism.php
+++ b/apps/files_external/lib/Lib/Auth/AuthMechanism.php
@@ -29,6 +29,8 @@ use OCA\Files_External\Lib\IdentifierTrait;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\StorageModifierTrait;
use OCA\Files_External\Lib\VisibilityTrait;
+use OCA\Files_External\Lib\IIdentifier;
+use OCA\Files_External\Lib\IFrontendDefintion;
/**
* Authentication mechanism
@@ -50,7 +52,7 @@ use OCA\Files_External\Lib\VisibilityTrait;
* - StorageModifierTrait
* Object can affect storage mounting
*/
-class AuthMechanism implements \JsonSerializable {
+class AuthMechanism implements \JsonSerializable, IIdentifier, IFrontendDefintion {
/** Standard authentication schemes */
public const SCHEME_NULL = 'null';
public const SCHEME_BUILTIN = 'builtin';
diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php
index 053d9b87952..afedfd213eb 100644
--- a/apps/files_external/lib/Lib/Backend/Backend.php
+++ b/apps/files_external/lib/Lib/Backend/Backend.php
@@ -30,6 +30,8 @@ use OCA\Files_External\Lib\PriorityTrait;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\StorageModifierTrait;
use OCA\Files_External\Lib\VisibilityTrait;
+use OCA\Files_External\Lib\IIdentifier;
+use OCA\Files_External\Lib\IFrontendDefintion;
/**
* Storage backend
@@ -55,7 +57,7 @@ use OCA\Files_External\Lib\VisibilityTrait;
* - StorageModifierTrait
* Object can affect storage mounting
*/
-class Backend implements \JsonSerializable {
+class Backend implements \JsonSerializable, IIdentifier, IFrontendDefintion {
use VisibilityTrait;
use FrontendDefinitionTrait;
use PriorityTrait;
diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
index b10d3a0b276..6b2dc8672f3 100644
--- a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
+++ b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
@@ -29,62 +29,45 @@ namespace OCA\Files_External\Lib;
trait FrontendDefinitionTrait {
/** @var string human-readable mechanism name */
- private $text;
+ private string $text = "";
/** @var DefinitionParameter[] parameters for mechanism */
- private $parameters = [];
+ private array $parameters = [];
/** @var string[] custom JS */
- private $customJs = [];
+ private array $customJs = [];
- /**
- * @return string
- */
- public function getText() {
+ public function getText(): string {
return $this->text;
}
- /**
- * @param string $text
- * @return $this
- */
- public function setText($text) {
+ public function setText(string $text): self {
$this->text = $text;
return $this;
}
- /**
- * @param FrontendDefinitionTrait $a
- * @param FrontendDefinitionTrait $b
- * @return int
- */
- public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) {
+ public static function lexicalCompare(IFrontendDefinition $a, IFrontendDefinition $b): int {
return strcmp($a->getText(), $b->getText());
}
/**
* @return DefinitionParameter[]
*/
- public function getParameters() {
+ public function getParameters(): array {
return $this->parameters;
}
/**
* @param DefinitionParameter[] $parameters
- * @return self
*/
- public function addParameters(array $parameters) {
+ public function addParameters(array $parameters): self {
foreach ($parameters as $parameter) {
$this->addParameter($parameter);
}
return $this;
}
- /**
- * @param DefinitionParameter $parameter
- * @return self
- */
- public function addParameter(DefinitionParameter $parameter) {
+ public function addParameter(DefinitionParameter $parameter): self {
$this->parameters[$parameter->getName()] = $parameter;
return $this;
}
@@ -92,7 +75,7 @@ trait FrontendDefinitionTrait {
/**
* @return string[]
*/
- public function getCustomJs() {
+ public function getCustomJs(): array {
return $this->customJs;
}
@@ -100,17 +83,15 @@ trait FrontendDefinitionTrait {
* @param string $custom
* @return self
*/
- public function addCustomJs($custom) {
+ public function addCustomJs(string $custom): self {
$this->customJs[] = $custom;
return $this;
}
/**
* Serialize into JSON for client-side JS
- *
- * @return array
*/
- public function jsonSerializeDefinition() {
+ public function jsonSerializeDefinition(): array {
$configuration = [];
foreach ($this->getParameters() as $parameter) {
$configuration[$parameter->getName()] = $parameter;
@@ -126,11 +107,8 @@ trait FrontendDefinitionTrait {
/**
* Check if parameters are satisfied in a StorageConfig
- *
- * @param StorageConfig $storage
- * @return bool
*/
- public function validateStorageDefinition(StorageConfig $storage) {
+ public function validateStorageDefinition(StorageConfig $storage): bool {
foreach ($this->getParameters() as $name => $parameter) {
$value = $storage->getBackendOption($name);
if (!is_null($value) || !$parameter->isOptional()) {
diff --git a/apps/files_external/lib/Lib/IFrontendDefinition.php b/apps/files_external/lib/Lib/IFrontendDefinition.php
new file mode 100644
index 00000000000..1a518a4ee76
--- /dev/null
+++ b/apps/files_external/lib/Lib/IFrontendDefinition.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * 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/>
+ *
+ */
+namespace OCA\Files_External\Lib;
+
+interface IFrontendDefintion {
+
+ public function getText(): string;
+
+ public function setText(string $text): self;
+
+ /**
+ * @return list<DefinitionParameter>
+ */
+ public function getParameters(): array;
+
+ /**
+ * @param DefinitionParameter[] $parameters
+ */
+ public function addParameters(array $parameters): self;
+
+ public function addParameter(DefinitionParameter $parameter): self;
+
+ /**
+ * @return string[]
+ */
+ public function getCustomJs(): array;
+
+ public function addCustomJs(string $custom): self;
+
+ /**
+ * Serialize into JSON for client-side JS
+ */
+ public function jsonSerializeDefinition(): array;
+
+ /**
+ * Check if parameters are satisfied in a StorageConfig
+ */
+ public function validateStorageDefinition(StorageConfig $storage): bool;
+}
diff --git a/apps/files_external/lib/Lib/IIdentifier.php b/apps/files_external/lib/Lib/IIdentifier.php
new file mode 100644
index 00000000000..b410f5333d5
--- /dev/null
+++ b/apps/files_external/lib/Lib/IIdentifier.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * 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/>
+ *
+ */
+namespace OCA\Files_External\Lib;
+
+interface IIdentifier {
+
+ public function getIdentifier(): string;
+
+ public function setIdentifier(string $identifier): self;
+}
diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/apps/files_external/lib/Lib/IdentifierTrait.php
index 37813795490..52eff147a02 100644
--- a/apps/files_external/lib/Lib/IdentifierTrait.php
+++ b/apps/files_external/lib/Lib/IdentifierTrait.php
@@ -28,27 +28,17 @@ namespace OCA\Files_External\Lib;
*/
trait IdentifierTrait {
- /** @var string */
- protected $identifier;
+ protected string $identifier = '';
/** @var string[] */
- protected $identifierAliases = [];
+ protected array $identifierAliases = [];
+ protected ?IIdentifier $deprecateTo = null;
- /** @var IdentifierTrait */
- protected $deprecateTo = null;
-
- /**
- * @return string
- */
- public function getIdentifier() {
+ public function getIdentifier(): string {
return $this->identifier;
}
- /**
- * @param string $identifier
- * @return $this
- */
- public function setIdentifier($identifier) {
+ public function setIdentifier(string $identifier): self {
$this->identifier = $identifier;
$this->identifierAliases[] = $identifier;
return $this;
@@ -57,39 +47,25 @@ trait IdentifierTrait {
/**
* @return string[]
*/
- public function getIdentifierAliases() {
+ public function getIdentifierAliases(): array {
return $this->identifierAliases;
}
- /**
- * @param string $alias
- * @return $this
- */
- public function addIdentifierAlias($alias) {
+ public function addIdentifierAlias(string $alias): self {
$this->identifierAliases[] = $alias;
return $this;
}
- /**
- * @return object|null
- */
- public function getDeprecateTo() {
+ public function getDeprecateTo(): ?IIdentifier {
return $this->deprecateTo;
}
- /**
- * @param object $destinationObject
- * @return self
- */
- public function deprecateTo($destinationObject) {
+ public function deprecateTo(IIdentifier $destinationObject): self {
$this->deprecateTo = $destinationObject;
return $this;
}
- /**
- * @return array
- */
- public function jsonSerializeIdentifier() {
+ public function jsonSerializeIdentifier(): array {
$data = [
'identifier' => $this->identifier,
'identifierAliases' => $this->identifierAliases,
diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/apps/files_external/lib/Lib/PriorityTrait.php
index 355f75a833a..299d25c9b40 100644
--- a/apps/files_external/lib/Lib/PriorityTrait.php
+++ b/apps/files_external/lib/Lib/PriorityTrait.php
@@ -47,13 +47,4 @@ trait PriorityTrait {
$this->priority = $priority;
return $this;
}
-
- /**
- * @param PriorityTrait $a
- * @param PriorityTrait $b
- * @return int
- */
- public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) {
- return ($a->getPriority() - $b->getPriority());
- }
}