-
Notifications
You must be signed in to change notification settings - Fork 40
/
ElasticsearchServiceProvider.php
49 lines (41 loc) · 1.14 KB
/
ElasticsearchServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Shift31\LaravelElasticsearch;
use Elasticsearch\ClientBuilder;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
class ElasticsearchServiceProvider extends ServiceProvider
{
const VERSION = '4.5.0';
/**
* @inheritdoc
*/
public function boot()
{
$this->package('shift31/laravel-elasticsearch', 'shift31');
}
/**
* @inheritdoc
*/
public function register()
{
$this->app->singleton('elasticsearch', function () {
$config = array_merge($this->loadDefaultConfig(), $this->app->config->get('shift31::elasticsearch'));
return ClientBuilder::fromConfig($config);
});
$this->app->booting(function () {
$loader = AliasLoader::getInstance();
$loader->alias('Es', 'Shift31\LaravelElasticsearch\Facades\Es');
});
}
/**
* @inheritdoc
*/
public function provides()
{
return ['elasticsearch'];
}
private function loadDefaultConfig()
{
return $this->app->files->getRequire(realpath(__DIR__ . '/../../config/elasticsearch.php'));
}
}