From fe2c6fe3aa7e0963811d692f45d4dbc43d887d7e Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Mon, 1 Feb 2021 14:51:51 -0500 Subject: [PATCH] Use primitive contextual binding --- src/Discussion/Search/DiscussionSearcher.php | 5 ++-- src/Search/AbstractSearcher.php | 6 ++-- src/Search/SearchMutators.php | 29 -------------------- src/Search/SearchServiceProvider.php | 6 ++-- src/User/Search/UserSearcher.php | 5 ++-- 5 files changed, 10 insertions(+), 41 deletions(-) delete mode 100644 src/Search/SearchMutators.php diff --git a/src/Discussion/Search/DiscussionSearcher.php b/src/Discussion/Search/DiscussionSearcher.php index 7104fd1312c..edc755b8c81 100644 --- a/src/Discussion/Search/DiscussionSearcher.php +++ b/src/Discussion/Search/DiscussionSearcher.php @@ -15,7 +15,6 @@ use Flarum\Search\AbstractSearcher; use Flarum\Search\GambitManager; use Flarum\Search\SearchCriteria; -use Flarum\Search\SearchMutators; use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Builder; @@ -36,9 +35,9 @@ class DiscussionSearcher extends AbstractSearcher * @param DiscussionRepository $discussions * @param Dispatcher $events * @param GambitManager $gambits - * @param SearchMutators $searchMutators + * @param array $searchMutators */ - public function __construct(DiscussionRepository $discussions, Dispatcher $events, GambitManager $gambits, SearchMutators $searchMutators) + public function __construct(DiscussionRepository $discussions, Dispatcher $events, GambitManager $gambits, array $searchMutators) { parent::__construct($gambits, $searchMutators); diff --git a/src/Search/AbstractSearcher.php b/src/Search/AbstractSearcher.php index 7fa0e8be579..9ccb33d59f6 100644 --- a/src/Search/AbstractSearcher.php +++ b/src/Search/AbstractSearcher.php @@ -22,11 +22,11 @@ abstract class AbstractSearcher protected $gambits; /** - * @var SearchMutators + * @var array */ protected $searchMutators; - public function __construct(GambitManager $gambits, SearchMutators $searchMutators) + public function __construct(GambitManager $gambits, array $searchMutators) { $this->gambits = $gambits; $this->searchMutators = $searchMutators; @@ -38,7 +38,7 @@ abstract protected function getSearch(Builder $query, User $actor): AbstractSear protected function mutateSearch(AbstractSearch $search, SearchCriteria $criteria) { - foreach ($this->searchMutators->getMutators() as $mutator) { + foreach ($this->searchMutators as $mutator) { $mutator($search, $criteria); } } diff --git a/src/Search/SearchMutators.php b/src/Search/SearchMutators.php deleted file mode 100644 index b07e84a74c7..00000000000 --- a/src/Search/SearchMutators.php +++ /dev/null @@ -1,29 +0,0 @@ -mutators = $mutators; - } - - public function getMutators(): array - { - return $this->mutators; - } -} diff --git a/src/Search/SearchServiceProvider.php b/src/Search/SearchServiceProvider.php index 2cbc1a7856c..fee38bf9557 100644 --- a/src/Search/SearchServiceProvider.php +++ b/src/Search/SearchServiceProvider.php @@ -112,13 +112,13 @@ public function boot() $this->app ->when($searcher) - ->needs(SearchMutators::class) + ->needs('$searchMutators') ->give(function () use ($searcher) { $searchMutators = Arr::get($this->app->make('flarum.simple_search.search_mutators'), $searcher, []); - return new SearchMutators(array_map(function ($mutator) { + return array_map(function ($mutator) { return ContainerUtil::wrapCallback($mutator, $this->app); - }, $searchMutators)); + }, $searchMutators); }); } } diff --git a/src/User/Search/UserSearcher.php b/src/User/Search/UserSearcher.php index 6392a736dcb..cecd7565128 100644 --- a/src/User/Search/UserSearcher.php +++ b/src/User/Search/UserSearcher.php @@ -13,7 +13,6 @@ use Flarum\Search\AbstractSearcher; use Flarum\Search\GambitManager; use Flarum\Search\SearchCriteria; -use Flarum\Search\SearchMutators; use Flarum\User\Event\Searching; use Flarum\User\User; use Flarum\User\UserRepository; @@ -40,9 +39,9 @@ class UserSearcher extends AbstractSearcher * @param UserRepository $users * @param Dispatcher $events * @param GambitManager $gambits - * @param SearchMutators $searchMutators + * @param array $searchMutators */ - public function __construct(UserRepository $users, Dispatcher $events, GambitManager $gambits, SearchMutators $searchMutators) + public function __construct(UserRepository $users, Dispatcher $events, GambitManager $gambits, array $searchMutators) { parent::__construct($gambits, $searchMutators);