aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-06 16:09:29 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-26 23:10:23 +0200
commit4a96e222588104f647f911857e370b3ab692ea22 (patch)
treec0859c504c83b8e4e6f11a2d1c39974ca338e63b /lib/public
parent579c1476a3ec5d9b93130c84a5cc1438b9bd03a9 (diff)
downloadnextcloud-server-4a96e222588104f647f911857e370b3ab692ea22.tar.gz
nextcloud-server-4a96e222588104f647f911857e370b3ab692ea22.zip
don't keep result types hard coded
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/Collaboration/Collaborators/ISearchResult.php20
-rw-r--r--lib/public/Collaboration/Collaborators/SearchResultType.php57
2 files changed, 67 insertions, 10 deletions
diff --git a/lib/public/Collaboration/Collaborators/ISearchResult.php b/lib/public/Collaboration/Collaborators/ISearchResult.php
index 87c787c040b..abea5df8598 100644
--- a/lib/public/Collaboration/Collaborators/ISearchResult.php
+++ b/lib/public/Collaboration/Collaborators/ISearchResult.php
@@ -31,39 +31,39 @@ namespace OCP\Collaboration\Collaborators;
*/
interface ISearchResult {
/**
- * @param string $type one of: users, groups, remotes, email, circles, lookup
+ * @param SearchResultType $type
* @param array $matches
* @param array|null $exactMatches
* @since 13.0.0
*/
- public function addResultSet($type, array $matches, array $exactMatches = null);
+ public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null);
/**
- * @param string $type one of: users, groups, remotes, email, circles, lookup
+ * @param SearchResultType $type
* @param string $collaboratorId
* @return bool
* @since 13.0.0
*/
- public function hasResult($type, $collaboratorId);
+ public function hasResult(SearchResultType $type, $collaboratorId);
/**
- * @param string $type one of: users, groups, remotes, email, circles, lookup
+ * @param SearchResultType $type
* @since 13.0.0
*/
- public function unsetResult($type);
+ public function unsetResult(SearchResultType $type);
/**
- * @param string $type one of: users, groups, remotes, email, circles, lookup
+ * @param SearchResultType $type
* @since 13.0.0
*/
- public function markExactIdMatch($type);
+ public function markExactIdMatch(SearchResultType $type);
/**
- * @param string $type one of: users, groups, remotes, email, circles, lookup
+ * @param SearchResultType $type
* @return bool
* @since 13.0.0
*/
- public function hasExactIdMatch($type);
+ public function hasExactIdMatch(SearchResultType $type);
/**
* @return array
diff --git a/lib/public/Collaboration/Collaborators/SearchResultType.php b/lib/public/Collaboration/Collaborators/SearchResultType.php
new file mode 100644
index 00000000000..569adb864e9
--- /dev/null
+++ b/lib/public/Collaboration/Collaborators/SearchResultType.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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\Collaborators;
+
+/**
+ * Class SearchResultType
+ *
+ * @package OCP\Collaboration\Collaborators
+ * @since 13.0.0
+ */
+class SearchResultType {
+ /** @var string */
+ protected $label;
+
+ public function __construct($label) {
+ $this->label = $this->getValidatedType($label);
+ }
+
+ public function getLabel() {
+ return $this->label;
+ }
+
+ protected function getValidatedType($type) {
+ $type = trim(strval($type));
+
+ if($type === '') {
+ throw new \InvalidArgumentException('Type must not be empty');
+ }
+
+ if(trim($type) === 'exact') {
+ throw new \InvalidArgumentException('Provided type is a reserved word');
+ }
+
+ return $type;
+ }
+}