diff options
Diffstat (limited to 'lib/Model/SearchRequest.php')
-rw-r--r-- | lib/Model/SearchRequest.php | 226 |
1 files changed, 138 insertions, 88 deletions
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index 0fce57a..1d21169 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -26,9 +26,11 @@ namespace OCA\FullTextSearch\Model; +use JsonSerializable; use OCA\FullTextSearch\Service\MiscService; +use OCP\FullTextSearch\Model\ISearchRequest; -class SearchRequest implements \JsonSerializable { +class SearchRequest implements ISearchRequest, JsonSerializable { /** @var array */ private $providers; @@ -89,52 +91,64 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getProviders() { + public function getProviders(): array { return $this->providers; } /** * @param array $providers + * + * @return ISearchRequest */ - public function setProviders($providers) { + public function setProviders(array $providers): ISearchRequest { $this->providers = $providers; + + return $this; } /** * @return string */ - public function getAuthor() { + public function getAuthor(): string { return $this->author; } /** * @param string $author + * + * @return ISearchRequest */ - public function setAuthor($author) { + public function setAuthor(string $author): ISearchRequest { $this->author = $author; + + return $this; } /** * @return string */ - public function getSearch() { + public function getSearch(): string { return $this->search; } /** * @param string $search + * + * @return ISearchRequest */ - public function setSearch($search) { + public function setSearch(string $search): ISearchRequest { $this->search = $search; + + return $this; } /** * */ - public function cleanSearch() { + public function cleanSearch(): ISearchRequest { $search = trim(str_replace(' ', ' ', $this->getSearch())); preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words); @@ -148,15 +162,17 @@ class SearchRequest implements \JsonSerializable { } $this->setSearch(implode(" ", $searchItems)); + + return $this; } /** - * @param $word + * @param string $word * * @return bool */ - private function searchQueryOptions($word) { + private function searchQueryOptions(string $word): bool { if (($pos = strpos($word, ':')) === false) { return false; } @@ -184,99 +200,111 @@ class SearchRequest implements \JsonSerializable { /** * @return int */ - public function getPage() { + public function getPage(): int { return $this->page; } /** * @param int $page + * + * @return ISearchRequest */ - public function setPage($page) { + public function setPage(int $page): ISearchRequest { if ($page < 1) { $page = 1; } $this->page = $page; + + return $this; } /** * @return int */ - public function getSize() { + public function getSize(): int { return $this->size; } /** * @param int $size + * + * @return ISearchRequest */ - public function setSize($size) { + public function setSize(int $size): ISearchRequest { $this->size = $size; + + return $this; } /** * @return array */ - public function getOptions() { + public function getOptions(): array { return $this->options; } /** * @param array $options + * + * @return ISearchRequest */ - public function setOptions($options) { + public function setOptions(array $options): ISearchRequest { $this->options = $options; + + return $this; } /** - * @param $key + * @param $option * @param $value * - * @return $this + * @return ISearchRequest */ - public function addOption($key, $value) { - $this->options[$key] = $value; + public function addOption(string $option, string $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param string $k - * @param array $array + * @param string $option + * @param array $value * - * @return SearchRequest + * @return ISearchRequest */ - public function addOptionArray($k, $array) { - $this->options[$k] = $array; + public function addOptionArray(string $option, array $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param string $k - * @param bool $bool + * @param string $option + * @param bool $value * - * @return SearchRequest + * @return ISearchRequest */ - public function addOptionBool($k, $bool) { - $this->options[$k] = $bool; + public function addOptionBool(string $option, bool $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param $key - * @param $value + * @param string $option + * @param string $value * - * @return $this + * @return ISearchRequest */ - public function addMultipleOption($key, $value) { - if (!array_key_exists($key, $this->options)) { - $this->options[$key] = []; + public function addMultipleOption(string $option, string $value): ISearchRequest { + if (!array_key_exists($option, $this->options)) { + $this->options[$option] = []; } - $this->options[$key][] = $value; + $this->options[$option][] = $value; return $this; } @@ -287,7 +315,7 @@ class SearchRequest implements \JsonSerializable { * * @return string */ - public function getOption($option, $default = '') { + public function getOption(string $option, string $default = ''): string { if (array_key_exists($option, $this->options)) { return $this->options[$option]; } @@ -302,7 +330,7 @@ class SearchRequest implements \JsonSerializable { * * @return array */ - public function getOptionArray($option, $default = []) { + public function getOptionArray(string $option, array $default = []): array { if (array_key_exists($option, $this->options)) { $options = $this->options[$option]; if (is_array($options)) { @@ -315,12 +343,12 @@ class SearchRequest implements \JsonSerializable { /** - * @param array $parts + * @param string $part * - * @return $this + * @return ISearchRequest */ - public function setParts($parts) { - $this->parts = $parts; + public function addPart(string $part): ISearchRequest { + $this->parts[] = $part; return $this; } @@ -328,24 +356,38 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getParts() { + public function getParts(): array { return $this->parts; } /** + * @since 15.0.0 + * + * @param array $parts + * + * @return ISearchRequest + */ + public function setParts(array $parts): ISearchRequest { + $this->parts = $parts; + + return $this; + } + + + /** * @return array */ - public function getFields() { + public function getFields(): array { return $this->fields; } /** * @param array $fields * - * @return $this + * @return ISearchRequest */ - public function setFields($fields) { + public function setFields(array $fields): ISearchRequest { $this->fields = $fields; return $this; @@ -353,11 +395,11 @@ class SearchRequest implements \JsonSerializable { /** - * @param $field + * @param string $field * - * @return $this + * @return ISearchRequest */ - public function limitToField($field) { + public function addLimitField(string $field): ISearchRequest { array_push($this->limitFields, $field); return $this; @@ -366,17 +408,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getLimitFields() { + public function getLimitFields(): array { return $this->limitFields; } /** - * @param $field + * @param string $field * - * @return $this + * @return ISearchRequest */ - public function addField($field) { + public function addField(string $field): ISearchRequest { $this->fields[] = $field; return $this; @@ -385,32 +427,40 @@ class SearchRequest implements \JsonSerializable { /** * @param string $tag + * + * @return ISearchRequest */ - public function addTag($tag) { + public function addTag(string $tag): ISearchRequest { $this->tags[] = $tag; + + return $this; } /** * @return array */ - public function getTags() { + public function getTags(): array { return $this->tags; } /** * @param array $tags + * + * @return ISearchRequest */ - public function setTags($tags) { + public function setTags(array $tags): ISearchRequest { $this->tags = $tags; + + return $this; } /** * @param array $tags * - * @return $this + * @return ISearchRequest */ - public function setMetaTags($tags) { + public function setMetaTags(array $tags): ISearchRequest { $this->metaTags = $tags; return $this; @@ -419,17 +469,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getMetaTags() { + public function getMetaTags(): array { return $this->metaTags; } /** - * @param string $tags + * @param string $tag * - * @return $this + * @return ISearchRequest */ - public function addMetaTag($tags) { - $this->metaTags[] = $tags; + public function addMetaTag(string $tag): ISearchRequest { + $this->metaTags[] = $tag; return $this; } @@ -438,9 +488,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $tags * - * @return $this + * @return ISearchRequest */ - public function setSubTags($tags) { + public function setSubTags(array $tags): ISearchRequest { $this->subTags = $tags; return $this; @@ -451,7 +501,7 @@ class SearchRequest implements \JsonSerializable { * * @return array */ - public function getSubTags($formatted = false) { + public function getSubTags(bool $formatted = false): array { if ($formatted === false) { return $this->subTags; } @@ -472,9 +522,9 @@ class SearchRequest implements \JsonSerializable { * @param string $source * @param string $tag * - * @return $this + * @return ISearchRequest */ - public function addSubTag($source, $tag) { + public function addSubTag(string $source, string $tag): ISearchRequest { if (!array_key_exists($source, $this->subTags)) { $this->subTags[$source] = []; } @@ -488,9 +538,9 @@ class SearchRequest implements \JsonSerializable { /** * @param string $field * - * @return $this + * @return ISearchRequest */ - public function addWildcardField($field) { + public function addWildcardField(string $field): ISearchRequest { $this->wildcardFields[] = $field; return $this; @@ -500,7 +550,7 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getWildcardFields() { + public function getWildcardFields(): array { return $this->wildcardFields; } @@ -508,7 +558,7 @@ class SearchRequest implements \JsonSerializable { // /** // * @param array $query // * -// * @return $this +// * @return ISearchRequest // */ // public function addWildcardQuery($query) { // $this->addWildcardQueries([$query]); @@ -519,7 +569,7 @@ class SearchRequest implements \JsonSerializable { // /** // * @param array $query // * -// * @return $this +// * @return ISearchRequest // */ // public function addWildcardQueries($query) { // array_push($this->wildcardQueries, $query); @@ -538,9 +588,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filter * - * @return $this + * @return ISearchRequest */ - public function addWildcardFilter($filter) { + public function addWildcardFilter(array $filter): ISearchRequest { $this->addWildcardFilters([$filter]); return $this; @@ -549,9 +599,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filters * - * @return $this + * @return ISearchRequest */ - public function addWildcardFilters($filters) { + public function addWildcardFilters(array $filters): ISearchRequest { array_push($this->wildcardFilters, $filters); return $this; @@ -560,17 +610,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getWildcardFilters() { + public function getWildcardFilters(): array { return $this->wildcardFilters; } /** - * @param array $filter + * @param string $filter * - * @return $this + * @return ISearchRequest */ - public function addRegexFilter($filter) { + public function addRegexFilter(string $filter): ISearchRequest { $this->addRegexFilters([$filter]); return $this; @@ -579,9 +629,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filters * - * @return $this + * @return ISearchRequest */ - public function addRegexFilters($filters) { + public function addRegexFilters(array $filters): ISearchRequest { array_push($this->regexFilters, $filters); return $this; @@ -590,7 +640,7 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getRegexFilters() { + public function getRegexFilters(): array { return $this->regexFilters; } @@ -619,7 +669,7 @@ class SearchRequest implements \JsonSerializable { * * @return SearchRequest */ - public static function fromJSON($json) { + public static function fromJSON($json): SearchRequest { return self::fromArray(json_decode($json, true)); } @@ -628,7 +678,7 @@ class SearchRequest implements \JsonSerializable { * * @return SearchRequest */ - public static function fromArray($arr) { + public static function fromArray($arr): SearchRequest { $providers = $arr['providers']; if (!is_array($providers)) { $providers = [$providers]; @@ -650,4 +700,4 @@ class SearchRequest implements \JsonSerializable { } -}
\ No newline at end of file +} |