| 1 | <?php |
||
| 13 | class ElasticsearchServiceProvider extends ServiceProvider implements DeferrableProvider |
||
| 14 | { |
||
| 15 | 71 | public function boot(): void |
|
| 19 | |||
| 20 | 71 | public function register(): void |
|
| 21 | { |
||
| 22 | 71 | $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 | 71 | }); |
|
| 43 | |||
| 44 | 71 | $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 | 71 | }); |
|
| 50 | 71 | } |
|
| 51 | |||
| 52 | 1 | public function provides() |
|
| 56 | } |
||
| 57 |