From a24981ca750de8254878e1d8ed186218d58becd6 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Mon, 1 Mar 2021 16:38:40 -0500 Subject: [PATCH] Introduce AbstractQueryState class --- src/Filter/FilterState.php | 77 +--------------------------- src/Query/AbstractQueryState.php | 87 ++++++++++++++++++++++++++++++++ src/Search/AbstractSearch.php | 4 +- 3 files changed, 91 insertions(+), 77 deletions(-) create mode 100644 src/Query/AbstractQueryState.php diff --git a/src/Filter/FilterState.php b/src/Filter/FilterState.php index cc5a4a2595..69c95c4382 100644 --- a/src/Filter/FilterState.php +++ b/src/Filter/FilterState.php @@ -9,79 +9,6 @@ namespace Flarum\Filter; -use Flarum\User\User; -use Illuminate\Database\Query\Builder; +use Flarum\Query\AbstractQueryState; -class FilterState -{ - /** - * @var Builder - */ - protected $query; - - /** - * @var User - */ - protected $actor; - - /** - * @var mixed - */ - protected $defaultSort = []; - - /** - * @param Builder $query - * @param User $actor - */ - public function __construct(Builder $query, User $actor, $defaultSort = []) - { - $this->query = $query; - $this->actor = $actor; - $this->defaultSort = $defaultSort; - } - - /** - * Get the query builder for the search results query. - * - * @return Builder - */ - public function getQuery() - { - return $this->query; - } - - /** - * Get the user who is performing the search. - * - * @return User - */ - public function getActor() - { - return $this->actor; - } - - /** - * Get the default sort order for the search. - * - * @return array - */ - public function getDefaultSort() - { - return $this->defaultSort; - } - - /** - * Set the default sort order for the search. This will only be applied if - * a sort order has not been specified in the search criteria. - * - * @param mixed $defaultSort An array of sort-order pairs, where the column - * is the key, and the order is the value. The order may be 'asc', - * 'desc', or an array of IDs to order by. - * Alternatively, a callable may be used. - * @return mixed - */ - public function setDefaultSort($defaultSort) - { - $this->defaultSort = $defaultSort; - } -} +class FilterState extends AbstractQueryState {} diff --git a/src/Query/AbstractQueryState.php b/src/Query/AbstractQueryState.php new file mode 100644 index 0000000000..257871961c --- /dev/null +++ b/src/Query/AbstractQueryState.php @@ -0,0 +1,87 @@ +query = $query; + $this->actor = $actor; + $this->defaultSort = $defaultSort; + } + + /** + * Get the query builder for the search results query. + * + * @return Builder + */ + public function getQuery() + { + return $this->query; + } + + /** + * Get the user who is performing the search. + * + * @return User + */ + public function getActor() + { + return $this->actor; + } + + /** + * Get the default sort order for the search. + * + * @return array + */ + public function getDefaultSort() + { + return $this->defaultSort; + } + + /** + * Set the default sort order for the search. This will only be applied if + * a sort order has not been specified in the search criteria. + * + * @param mixed $defaultSort An array of sort-order pairs, where the column + * is the key, and the order is the value. The order may be 'asc', + * 'desc', or an array of IDs to order by. + * Alternatively, a callable may be used. + * @return mixed + */ + public function setDefaultSort($defaultSort) + { + $this->defaultSort = $defaultSort; + } +} diff --git a/src/Search/AbstractSearch.php b/src/Search/AbstractSearch.php index adac8ceb23..ce9b4a77da 100644 --- a/src/Search/AbstractSearch.php +++ b/src/Search/AbstractSearch.php @@ -9,13 +9,13 @@ namespace Flarum\Search; -use Flarum\Filter\FilterState; +use Flarum\Query\AbstractQueryState; /** * @deprecated, use SearchState instead. * These methods should be transferred over to SearchState in beta 17. */ -class AbstractSearch extends FilterState +class AbstractSearch extends AbstractQueryState { /** * @var GambitInterface[]