1 | <?php |
||
13 | class ElasticsearchServiceProvider extends ServiceProvider implements DeferrableProvider |
||
14 | { |
||
15 | 14 | public function boot(): void |
|
19 | |||
20 | 14 | public function register(): void |
|
21 | { |
||
22 | 14 | $this->app->singleton(Client::class, static function (Application $app) { |
|
23 | // Logger instance |
||
24 | $config = $app['config']->get('services.elastic_search'); |
||
25 | |||
26 | $params = [ |
||
27 | 'hosts' => $config['hosts'], |
||
28 | ]; |
||
29 | |||
30 | if (! empty($config['connectionParams'])) { |
||
31 | $params['connectionParams'] = $config['connectionParams']; |
||
32 | } |
||
33 | |||
34 | $logger = ! empty($config['log_channel']) ? $app['log']->stack($config['log_channel']) : null; |
||
35 | if ($logger) { |
||
36 | $params['logger'] = $logger; |
||
37 | } |
||
38 | |||
39 | $client = ClientBuilder::fromConfig($params); |
||
40 | |||
41 | return $client; |
||
42 | 14 | }); |
|
43 | |||
44 | 14 | $this->app->singleton(ElasticsearchManagerContract::class, static function (Application $app) { |
|
45 | $client = $app->make(Client::class); |
||
46 | $enabled = (bool) $app['config']->get('services.elastic_search.enabled', false); |
||
47 | |||
48 | return new ElasticsearchManager($client, $enabled); |
||
49 | 14 | }); |
|
50 | 14 | } |
|
51 | |||
52 | 1 | public function provides() |
|
56 | } |
||
57 |