1 | <?php |
||
19 | class ElasticSearchServiceProvider extends ServiceProvider |
||
20 | { |
||
21 | protected $defer = true; |
||
22 | |||
23 | 11 | public function boot(): void |
|
27 | |||
28 | 11 | public function register(): void |
|
29 | { |
||
30 | $this->app->singleton(Client::class, function (Application $app) { |
||
31 | // Logger instance |
||
32 | $config = $app['config']->get('services.elastic_search'); |
||
33 | |||
34 | $params = [ |
||
35 | 'hosts' => $config['hosts'], |
||
36 | ]; |
||
37 | |||
38 | if (! empty($config['connectionParams'])) { |
||
39 | $params['connectionParams'] = $config['connectionParams']; |
||
40 | } |
||
41 | |||
42 | $logger = ! empty($config['log_channel']) ? $app['log']->stack($config['log_channel']) : null; |
||
43 | if ($logger) { |
||
44 | $params['logger'] = $logger; |
||
45 | } |
||
46 | |||
47 | $client = ClientBuilder::fromConfig($params); |
||
48 | |||
49 | return $client; |
||
50 | 11 | }); |
|
51 | |||
52 | 11 | $this->app->singleton(ElasticSearchManagerContract::class, function (Application $app) { |
|
53 | $client = $app->make(Client::class); |
||
54 | $enabled = (bool) $app['config']->get('services.elastic_search.enabled', false); |
||
55 | |||
56 | return new ElasticSearchManager($client, $enabled); |
||
57 | 11 | }); |
|
58 | 11 | } |
|
59 | |||
60 | 1 | public function provides() |
|
64 | } |
||
65 |