Skip to content

Commit

Permalink
new abstract ADiscoverableReferenceProvider that only implements json…
Browse files Browse the repository at this point in the history
…Serialize

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Dec 19, 2022
1 parent 199eb71 commit 256d7a4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
11 changes: 1 addition & 10 deletions core/Controller/ReferenceApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julien Veyssier <eneiluj@posteo.net>
*
* @author Julien Veyssier <eneiluj@posteo.net>
*
* @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 <http://www.gnu.org/licenses/>.
*/

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 256d7a4

Please sign in to comment.