From 7ef72685073180864adfedc28e3ef4d0b15b8f6f Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Mon, 5 Dec 2022 12:46:19 +0100 Subject: [PATCH] new abstract ADiscoverableReferenceProvider that only implements jsonSerialize Signed-off-by: Julien Veyssier --- core/Controller/ReferenceApiController.php | 11 +---- .../ADiscoverableReferenceProvider.php | 47 +++++++++++++++++++ .../IDiscoverableReferenceProvider.php | 6 +++ 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 lib/public/Collaboration/Reference/ADiscoverableReferenceProvider.php diff --git a/core/Controller/ReferenceApiController.php b/core/Controller/ReferenceApiController.php index 280e77787100d..9482038753cf7 100644 --- a/core/Controller/ReferenceApiController.php +++ b/core/Controller/ReferenceApiController.php @@ -107,16 +107,7 @@ public function getProvidersInfo(): DataResponse { } $jsonProviders = array_map(static function (IDiscoverableReferenceProvider $provider) { - $providerInfo = [ - 'id' => $provider->getId(), - 'title' => $provider->getTitle(), - 'icon_url' => $provider->getIconUrl(), - 'order' => $provider->getOrder(), - ]; - if ($provider instanceof ISearchableReferenceProvider) { - $providerInfo['search_providers_ids'] = $provider->getSupportedSearchProviderIds(); - } - return $providerInfo; + return $provider->jsonSerialize(); }, $providers); return new DataResponse($jsonProviders); } diff --git a/lib/public/Collaboration/Reference/ADiscoverableReferenceProvider.php b/lib/public/Collaboration/Reference/ADiscoverableReferenceProvider.php new file mode 100644 index 0000000000000..56b97957a0238 --- /dev/null +++ b/lib/public/Collaboration/Reference/ADiscoverableReferenceProvider.php @@ -0,0 +1,47 @@ + + * + * @author Julien Veyssier + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + */ + +namespace OCP\Collaboration\Reference; + +/** + * @since 26.0.0 + */ +abstract class ADiscoverableReferenceProvider implements IDiscoverableReferenceProvider { + + /** + * @inheritDoc + */ + public function jsonSerialize(): array { + $json = [ + 'id' => $this->getId(), + 'title' => $this->getTitle(), + 'icon_url' => $this->getIconUrl(), + 'order' => $this->getOrder(), + ]; + if ($this instanceof ISearchableReferenceProvider) { + $json['search_providers_ids'] = $this->getSupportedSearchProviderIds(); + } + return $json; + } +} diff --git a/lib/public/Collaboration/Reference/IDiscoverableReferenceProvider.php b/lib/public/Collaboration/Reference/IDiscoverableReferenceProvider.php index 4e54d50f6ff37..847e03c602ec2 100644 --- a/lib/public/Collaboration/Reference/IDiscoverableReferenceProvider.php +++ b/lib/public/Collaboration/Reference/IDiscoverableReferenceProvider.php @@ -51,4 +51,10 @@ public function getOrder(): int; * @since 26.0.0 */ public function getIconUrl(): string; + + /** + * @return array representation of the provider + * @since 26.0.0 + */ + public function jsonSerialize(): array; }