|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This file is part of Scout Extended. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Algolia Team <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Algolia\ScoutExtended; |
|
15
|
|
|
|
|
16
|
|
|
use Algolia\AlgoliaSearch\SearchClient; |
|
17
|
|
|
use Illuminate\Support\ServiceProvider; |
|
18
|
|
|
use Laravel\Scout\ScoutServiceProvider; |
|
19
|
|
|
use Algolia\ScoutExtended\Jobs\UpdateJob; |
|
20
|
|
|
use Algolia\AlgoliaSearch\AnalyticsClient; |
|
21
|
|
|
use Algolia\ScoutExtended\Engines\AlgoliaEngine; |
|
22
|
|
|
use Algolia\ScoutExtended\Managers\EngineManager; |
|
23
|
|
|
use Algolia\ScoutExtended\Helpers\SearchableFinder; |
|
24
|
|
|
use Algolia\ScoutExtended\Console\Commands\SyncCommand; |
|
25
|
|
|
use Algolia\ScoutExtended\Console\Commands\FlushCommand; |
|
26
|
|
|
use Algolia\ScoutExtended\Searchable\AggregatorObserver; |
|
27
|
|
|
use Algolia\ScoutExtended\Console\Commands\ImportCommand; |
|
28
|
|
|
use Algolia\ScoutExtended\Console\Commands\StatusCommand; |
|
29
|
|
|
use Algolia\ScoutExtended\Console\Commands\OptimizeCommand; |
|
30
|
|
|
use Algolia\ScoutExtended\Console\Commands\ReImportCommand; |
|
31
|
|
|
use Algolia\ScoutExtended\Console\Commands\MakeAggregatorCommand; |
|
32
|
|
|
|
|
33
|
|
|
final class ScoutExtendedServiceProvider extends ServiceProvider |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
60 |
|
public function boot(): void |
|
39
|
|
|
{ |
|
40
|
60 |
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'algolia'); |
|
|
|
|
|
|
41
|
60 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
60 |
|
public function register(): void |
|
47
|
|
|
{ |
|
48
|
60 |
|
$this->app->register(ScoutServiceProvider::class); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
60 |
|
$this->registerBinds(); |
|
51
|
60 |
|
$this->registerCommands(); |
|
52
|
60 |
|
$this->registerMacros(); |
|
53
|
60 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Binds Algolia services into the container. |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
60 |
|
private function registerBinds(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->app->bind(Algolia::class, function () { |
|
|
|
|
|
|
63
|
23 |
|
return new Algolia($this->app); |
|
|
|
|
|
|
64
|
60 |
|
}); |
|
65
|
|
|
|
|
66
|
60 |
|
$this->app->alias(Algolia::class, 'algolia'); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->app->singleton(EngineManager::class, function ($app) { |
|
|
|
|
|
|
69
|
55 |
|
return new EngineManager($app); |
|
70
|
60 |
|
}); |
|
71
|
|
|
|
|
72
|
60 |
|
$this->app->alias(EngineManager::class, \Laravel\Scout\EngineManager::class); |
|
73
|
|
|
|
|
74
|
|
|
$this->app->bind(AlgoliaEngine::class, function (): AlgoliaEngine { |
|
75
|
53 |
|
return $this->app->make(\Laravel\Scout\EngineManager::class)->createAlgoliaDriver(); |
|
|
|
|
|
|
76
|
60 |
|
}); |
|
77
|
|
|
|
|
78
|
60 |
|
$this->app->alias(AlgoliaEngine::class, 'algolia.engine'); |
|
79
|
|
|
$this->app->bind(SearchClient::class, function (): SearchClient { |
|
80
|
52 |
|
return $this->app->make('algolia.engine')->getClient(); |
|
81
|
60 |
|
}); |
|
82
|
|
|
|
|
83
|
60 |
|
$this->app->alias(SearchClient::class, 'algolia.client'); |
|
84
|
|
|
|
|
85
|
|
|
$this->app->bind(AnalyticsClient::class, function (): AnalyticsClient { |
|
86
|
1 |
|
return AnalyticsClient::create(config('scout.algolia.id'), config('scout.algolia.secret')); |
|
87
|
60 |
|
}); |
|
88
|
|
|
|
|
89
|
60 |
|
$this->app->alias(AnalyticsClient::class, 'algolia.analytics'); |
|
90
|
|
|
|
|
91
|
60 |
|
$this->app->singleton(AggregatorObserver::class, AggregatorObserver::class); |
|
92
|
60 |
|
$this->app->bind(\Laravel\Scout\Builder::class, Builder::class); |
|
93
|
|
|
|
|
94
|
|
|
$this->app->bind(SearchableFinder::class, function () { |
|
95
|
17 |
|
return new SearchableFinder($this->app); |
|
|
|
|
|
|
96
|
60 |
|
}); |
|
97
|
60 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Register artisan commands. |
|
101
|
|
|
* |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
60 |
|
private function registerCommands(): void |
|
105
|
|
|
{ |
|
106
|
60 |
|
if ($this->app->runningInConsole()) { |
|
|
|
|
|
|
107
|
60 |
|
$this->commands([ |
|
|
|
|
|
|
108
|
60 |
|
MakeAggregatorCommand::class, |
|
109
|
|
|
ImportCommand::class, |
|
110
|
|
|
FlushCommand::class, |
|
111
|
|
|
OptimizeCommand::class, |
|
112
|
|
|
ReImportCommand::class, |
|
113
|
|
|
StatusCommand::class, |
|
114
|
|
|
SyncCommand::class, |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
60 |
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Register macros. |
|
121
|
|
|
* |
|
122
|
|
|
* @return void |
|
123
|
|
|
*/ |
|
124
|
60 |
|
private function registerMacros(): void |
|
125
|
|
|
{ |
|
126
|
|
|
\Illuminate\Database\Eloquent\Builder::macro('transform', function (array $array, array $transformers = null) { |
|
127
|
15 |
|
foreach ($transformers ?? UpdateJob::getTransformers() as $transformer) { |
|
128
|
15 |
|
$array = app($transformer)->transform($this->getModel(), $array); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
15 |
|
return $array; |
|
132
|
60 |
|
}); |
|
133
|
|
|
|
|
134
|
|
|
\Illuminate\Database\Eloquent\Builder::macro('getSearchableIndex', function () { |
|
135
|
|
|
$client = $this->getModel()->searchableUsing()->getClient(); |
|
136
|
|
|
|
|
137
|
|
|
return $client->initIndex($this->getModel()->searchableAs()); |
|
138
|
60 |
|
}); |
|
139
|
60 |
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.