Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix(OCM): Make the public API only rely on OCP #41150

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/private/OCM/Model/OCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@

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;
Expand All @@ -62,9 +62,9 @@ public function isEnabled(): bool {
/**
* @param string $apiVersion
*
* @return OCMProvider
* @return $this
*/
public function setApiVersion(string $apiVersion): self {
public function setApiVersion(string $apiVersion): static {
$this->apiVersion = $apiVersion;

return $this;
Expand All @@ -80,9 +80,9 @@ public function getApiVersion(): string {
/**
* @param string $endPoint
*
* @return OCMProvider
* @return $this
*/
public function setEndPoint(string $endPoint): self {
public function setEndPoint(string $endPoint): static {
$this->endPoint = $endPoint;

return $this;
Expand All @@ -96,29 +96,29 @@ public function getEndPoint(): string {
}

/**
* @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;
Expand Down Expand Up @@ -151,11 +151,11 @@ public function extractProtocolEntry(string $resourceName, string $protocol): st
*
* @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'] ?? '');
Expand Down
18 changes: 8 additions & 10 deletions lib/private/OCM/Model/OCMResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

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 = [];
Expand All @@ -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;
Expand All @@ -60,9 +59,9 @@ public function getName(): string {
/**
* @param string[] $shareTypes
*
* @return OCMResource
* @return $this
*/
public function setShareTypes(array $shareTypes): self {
public function setShareTypes(array $shareTypes): static {
$this->shareTypes = $shareTypes;

return $this;
Expand All @@ -80,7 +79,7 @@ public function getShareTypes(): array {
*
* @return $this
*/
public function setProtocols(array $protocols): self {
public function setProtocols(array $protocols): static {
$this->protocols = $protocols;

return $this;
Expand All @@ -98,17 +97,16 @@ public function getProtocols(): array {
*
* @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[],
Expand Down
47 changes: 31 additions & 16 deletions lib/public/OCM/IOCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace OCP\OCM;

use OC\OCM\Model\OCMResource;
use JsonSerializable;
use OCP\OCM\Exceptions\OCMArgumentException;
use OCP\OCM\Exceptions\OCMProviderException;

Expand All @@ -35,16 +35,16 @@
* @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 ?
Expand All @@ -59,10 +59,10 @@ public function isEnabled(): bool;
*
* @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
Expand All @@ -77,10 +77,10 @@ public function getApiVersion(): string;
*
* @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
Expand All @@ -93,22 +93,22 @@ public function getEndPoint(): string;
/**
* 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
Expand All @@ -135,9 +135,24 @@ public function extractProtocolEntry(string $resourceName, string $protocol): st
*
* @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;
}
30 changes: 21 additions & 9 deletions lib/public/OCM/IOCMResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@

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
Expand All @@ -56,10 +58,10 @@ public function getName(): string;
*
* @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
Expand All @@ -74,10 +76,10 @@ public function getShareTypes(): array;
*
* @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
Expand All @@ -92,8 +94,18 @@ public function getProtocols(): array;
*
* @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;
}