1
|
|
|
<?php namespace Cviebrock\LaravelElasticsearch; |
2
|
|
|
|
3
|
|
|
use Elasticsearch\Client; |
4
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
5
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
6
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ServiceProvider |
11
|
|
|
* |
12
|
|
|
* @package Cviebrock\LaravelElasticsearch |
13
|
|
|
*/ |
14
|
|
|
class ServiceProvider extends BaseServiceProvider |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Bootstrap the application services. |
19
|
|
|
*/ |
20
|
|
|
public function boot() |
21
|
|
|
{ |
22
|
|
|
$this->setUpConfig(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register the application services. |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function register() |
31
|
|
|
{ |
32
|
|
|
$app = $this->app; |
33
|
|
|
|
34
|
|
|
$app->singleton('elasticsearch.factory', function($app) { |
|
|
|
|
35
|
|
|
return new Factory(); |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
$app->singleton('elasticsearch', function($app) { |
39
|
|
|
return new Manager($app, $app['elasticsearch.factory']); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$app->singleton(Client::class, function($app) { |
43
|
|
|
return $app['elasticsearch']->connection(); |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
if ($app instanceof LumenApplication) { |
|
|
|
|
47
|
|
|
$this->withLumenFacades(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function setUpConfig() |
52
|
|
|
{ |
53
|
|
|
$source = dirname(__DIR__) . '/config/elasticsearch.php'; |
54
|
|
|
|
55
|
|
|
if ($this->app instanceof LaravelApplication) { |
|
|
|
|
56
|
|
|
$this->publishes([$source => config_path('elasticsearch.php')], 'config'); |
57
|
|
|
} elseif ($this->app instanceof LumenApplication) { |
|
|
|
|
58
|
|
|
$this->app->configure('elasticsearch'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->mergeConfigFrom($source, 'elasticsearch'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function withLumenFacades() |
65
|
|
|
{ |
66
|
|
|
class_alias(Facade::class, 'Elasticsearch'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.