Skip to content

Commit

Permalink
Use primitive contextual binding
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Feb 10, 2021
1 parent 1e24a93 commit fe2c6fe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 41 deletions.
5 changes: 2 additions & 3 deletions src/Discussion/Search/DiscussionSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/Search/AbstractSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
29 changes: 0 additions & 29 deletions src/Search/SearchMutators.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Search/SearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/User/Search/UserSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit fe2c6fe

Please sign in to comment.