summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-11-06 09:45:34 +0100
committerGitHub <noreply@github.com>2023-11-06 09:45:34 +0100
commita9343edd57bed750b198b86873a4b696c6cfb8f7 (patch)
treee50aec003b82e9d4edd4cd1baa3b6abc056a86cc
parent91d9fa0a8d36dcef871b04bfd97583bf1082c2c6 (diff)
parent8dbc4e9eec4c0e24fcca4b87c782e1f975b3e802 (diff)
downloadnextcloud-server-a9343edd57bed750b198b86873a4b696c6cfb8f7.tar.gz
nextcloud-server-a9343edd57bed750b198b86873a4b696c6cfb8f7.zip
Merge pull request #41150 from nextcloud/backport/40885/stable27
[stable27] fix(OCM): Make the public API only rely on OCP
-rw-r--r--lib/private/OCM/Model/OCMProvider.php34
-rw-r--r--lib/private/OCM/Model/OCMResource.php18
-rw-r--r--lib/public/OCM/IOCMProvider.php47
-rw-r--r--lib/public/OCM/IOCMResource.php30
4 files changed, 77 insertions, 52 deletions
diff --git a/lib/private/OCM/Model/OCMProvider.php b/lib/private/OCM/Model/OCMProvider.php
index 44f4fbebc10..1a8d943f79f 100644
--- a/lib/private/OCM/Model/OCMProvider.php
+++ b/lib/private/OCM/Model/OCMProvider.php
@@ -26,27 +26,27 @@ declare(strict_types=1);
namespace OC\OCM\Model;
-use JsonSerializable;
use OCP\OCM\Exceptions\OCMArgumentException;
use OCP\OCM\Exceptions\OCMProviderException;
use OCP\OCM\IOCMProvider;
+use OCP\OCM\IOCMResource;
/**
* @since 28.0.0
*/
-class OCMProvider implements IOCMProvider, JsonSerializable {
+class OCMProvider implements IOCMProvider {
private bool $enabled = false;
private string $apiVersion = '';
private string $endPoint = '';
- /** @var OCMResource[] */
+ /** @var IOCMResource[] */
private array $resourceTypes = [];
/**
* @param bool $enabled
*
- * @return OCMProvider
+ * @return $this
*/
- public function setEnabled(bool $enabled): self {
+ public function setEnabled(bool $enabled): static {
$this->enabled = $enabled;
return $this;
@@ -62,9 +62,9 @@ class OCMProvider implements IOCMProvider, JsonSerializable {
/**
* @param string $apiVersion
*
- * @return OCMProvider
+ * @return $this
*/
- public function setApiVersion(string $apiVersion): self {
+ public function setApiVersion(string $apiVersion): static {
$this->apiVersion = $apiVersion;
return $this;
@@ -80,9 +80,9 @@ class OCMProvider implements IOCMProvider, JsonSerializable {
/**
* @param string $endPoint
*
- * @return OCMProvider
+ * @return $this
*/
- public function setEndPoint(string $endPoint): self {
+ public function setEndPoint(string $endPoint): static {
$this->endPoint = $endPoint;
return $this;
@@ -96,29 +96,29 @@ class OCMProvider implements IOCMProvider, JsonSerializable {
}
/**
- * @param OCMResource $resource
+ * @param IOCMResource $resource
*
* @return $this
*/
- public function addResourceType(OCMResource $resource): self {
+ public function addResourceType(IOCMResource $resource): static {
$this->resourceTypes[] = $resource;
return $this;
}
/**
- * @param OCMResource[] $resourceTypes
+ * @param IOCMResource[] $resourceTypes
*
- * @return OCMProvider
+ * @return $this
*/
- public function setResourceTypes(array $resourceTypes): self {
+ public function setResourceTypes(array $resourceTypes): static {
$this->resourceTypes = $resourceTypes;
return $this;
}
/**
- * @return OCMResource[]
+ * @return IOCMResource[]
*/
public function getResourceTypes(): array {
return $this->resourceTypes;
@@ -151,11 +151,11 @@ class OCMProvider implements IOCMProvider, JsonSerializable {
*
* @param array $data
*
- * @return self
+ * @return $this
* @throws OCMProviderException in case a descent provider cannot be generated from data
* @see self::jsonSerialize()
*/
- public function import(array $data): self {
+ public function import(array $data): static {
$this->setEnabled(is_bool($data['enabled'] ?? '') ? $data['enabled'] : false)
->setApiVersion((string)($data['apiVersion'] ?? ''))
->setEndPoint($data['endPoint'] ?? '');
diff --git a/lib/private/OCM/Model/OCMResource.php b/lib/private/OCM/Model/OCMResource.php
index 12948aa8949..c4a91f2eabf 100644
--- a/lib/private/OCM/Model/OCMResource.php
+++ b/lib/private/OCM/Model/OCMResource.php
@@ -26,13 +26,12 @@ declare(strict_types=1);
namespace OC\OCM\Model;
-use JsonSerializable;
use OCP\OCM\IOCMResource;
/**
* @since 28.0.0
*/
-class OCMResource implements IOCMResource, JsonSerializable {
+class OCMResource implements IOCMResource {
private string $name = '';
/** @var string[] */
private array $shareTypes = [];
@@ -42,9 +41,9 @@ class OCMResource implements IOCMResource, JsonSerializable {
/**
* @param string $name
*
- * @return OCMResource
+ * @return $this
*/
- public function setName(string $name): self {
+ public function setName(string $name): static {
$this->name = $name;
return $this;
@@ -60,9 +59,9 @@ class OCMResource implements IOCMResource, JsonSerializable {
/**
* @param string[] $shareTypes
*
- * @return OCMResource
+ * @return $this
*/
- public function setShareTypes(array $shareTypes): self {
+ public function setShareTypes(array $shareTypes): static {
$this->shareTypes = $shareTypes;
return $this;
@@ -80,7 +79,7 @@ class OCMResource implements IOCMResource, JsonSerializable {
*
* @return $this
*/
- public function setProtocols(array $protocols): self {
+ public function setProtocols(array $protocols): static {
$this->protocols = $protocols;
return $this;
@@ -98,17 +97,16 @@ class OCMResource implements IOCMResource, JsonSerializable {
*
* @param array $data
*
- * @return self
+ * @return $this
* @see self::jsonSerialize()
*/
- public function import(array $data): self {
+ public function import(array $data): static {
return $this->setName((string)($data['name'] ?? ''))
->setShareTypes($data['shareTypes'] ?? [])
->setProtocols($data['protocols'] ?? []);
}
/**
- *
* @return array{
* name: string,
* shareTypes: string[],
diff --git a/lib/public/OCM/IOCMProvider.php b/lib/public/OCM/IOCMProvider.php
index f99ccf1cd23..6eebf13a589 100644
--- a/lib/public/OCM/IOCMProvider.php
+++ b/lib/public/OCM/IOCMProvider.php
@@ -26,7 +26,7 @@ declare(strict_types=1);
namespace OCP\OCM;
-use OC\OCM\Model\OCMResource;
+use JsonSerializable;
use OCP\OCM\Exceptions\OCMArgumentException;
use OCP\OCM\Exceptions\OCMProviderException;
@@ -35,16 +35,16 @@ use OCP\OCM\Exceptions\OCMProviderException;
* @link https://github.com/cs3org/OCM-API/
* @since 28.0.0
*/
-interface IOCMProvider {
+interface IOCMProvider extends JsonSerializable {
/**
* enable OCM
*
* @param bool $enabled
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setEnabled(bool $enabled): self;
+ public function setEnabled(bool $enabled): static;
/**
* is set as enabled ?
@@ -59,10 +59,10 @@ interface IOCMProvider {
*
* @param string $apiVersion
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setApiVersion(string $apiVersion): self;
+ public function setApiVersion(string $apiVersion): static;
/**
* returns API version
@@ -77,10 +77,10 @@ interface IOCMProvider {
*
* @param string $endPoint
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setEndPoint(string $endPoint): self;
+ public function setEndPoint(string $endPoint): static;
/**
* get configured endpoint
@@ -93,22 +93,22 @@ interface IOCMProvider {
/**
* add a single resource to the object
*
- * @param OCMResource $resource
+ * @param IOCMResource $resource
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function addResourceType(OCMResource $resource): self;
+ public function addResourceType(IOCMResource $resource): static;
/**
* set resources
*
- * @param OCMResource[] $resourceTypes
+ * @param IOCMResource[] $resourceTypes
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setResourceTypes(array $resourceTypes): self;
+ public function setResourceTypes(array $resourceTypes): static;
/**
* get all set resources
@@ -135,9 +135,24 @@ interface IOCMProvider {
*
* @param array<string, int|string|bool|array> $data
*
- * @return self
+ * @return $this
* @throws OCMProviderException in case a descent provider cannot be generated from data
* @since 28.0.0
*/
- public function import(array $data): self;
+ public function import(array $data): static;
+
+ /**
+ * @return array{
+ * enabled: bool,
+ * apiVersion: string,
+ * endPoint: string,
+ * resourceTypes: array{
+ * name: string,
+ * shareTypes: string[],
+ * protocols: array<string, string>
+ * }[]
+ * }
+ * @since 28.0.0
+ */
+ public function jsonSerialize(): array;
}
diff --git a/lib/public/OCM/IOCMResource.php b/lib/public/OCM/IOCMResource.php
index 381af61cecc..242c77116f1 100644
--- a/lib/public/OCM/IOCMResource.php
+++ b/lib/public/OCM/IOCMResource.php
@@ -26,22 +26,24 @@ declare(strict_types=1);
namespace OCP\OCM;
+use JsonSerializable;
+
/**
* Model based on the Open Cloud Mesh Discovery API
*
* @link https://github.com/cs3org/OCM-API/
* @since 28.0.0
*/
-interface IOCMResource {
+interface IOCMResource extends JsonSerializable {
/**
* set name of the resource
*
* @param string $name
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setName(string $name): self;
+ public function setName(string $name): static;
/**
* get name of the resource
@@ -56,10 +58,10 @@ interface IOCMResource {
*
* @param string[] $shareTypes
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setShareTypes(array $shareTypes): self;
+ public function setShareTypes(array $shareTypes): static;
/**
* get share types
@@ -74,10 +76,10 @@ interface IOCMResource {
*
* @param array<string, string> $protocols
*
- * @return self
+ * @return $this
* @since 28.0.0
*/
- public function setProtocols(array $protocols): self;
+ public function setProtocols(array $protocols): static;
/**
* get configured protocols
@@ -92,8 +94,18 @@ interface IOCMResource {
*
* @param array $data
*
- * @return self
+ * @return $this
+ * @since 28.0.0
+ */
+ public function import(array $data): static;
+
+ /**
+ * @return array{
+ * name: string,
+ * shareTypes: string[],
+ * protocols: array<string, string>
+ * }
* @since 28.0.0
*/
- public function import(array $data): self;
+ public function jsonSerialize(): array;
}