|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Laratrade\Indicators; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Laratrade\Indicators\Contracts\IndicatorManager as IndicatorManagerContract; |
|
7
|
|
|
|
|
8
|
|
|
class IndicatorServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Indicates if loading of the provider is deferred. |
|
12
|
|
|
* |
|
13
|
|
|
* @var bool |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $defer = true; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Register the service provider. |
|
19
|
|
|
*/ |
|
20
|
10 |
|
public function register() |
|
21
|
|
|
{ |
|
22
|
|
|
$this |
|
23
|
10 |
|
->configure() |
|
24
|
10 |
|
->offerPublishing() |
|
25
|
10 |
|
->registerManager(); |
|
26
|
10 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Setup the configuration. |
|
30
|
|
|
* |
|
31
|
|
|
* @return $this |
|
32
|
|
|
*/ |
|
33
|
10 |
|
protected function configure() |
|
34
|
|
|
{ |
|
35
|
10 |
|
$this->mergeConfigFrom( |
|
36
|
10 |
|
__DIR__ . '/../config/indicators.php', |
|
37
|
10 |
|
'indicators' |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
10 |
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Setup the resource publishing group. |
|
45
|
|
|
* |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
10 |
|
protected function offerPublishing() |
|
49
|
|
|
{ |
|
50
|
10 |
|
if ($this->app->runningInConsole()) { |
|
51
|
10 |
|
$this->publishes([ |
|
52
|
10 |
|
__DIR__ . '/../config/indicators.php' => config_path('indicators.php'), |
|
53
|
10 |
|
], 'indicators'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
10 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Register the indicator manager. |
|
61
|
|
|
* |
|
62
|
|
|
* @return $this |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function registerManager() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->app->singleton(IndicatorManagerContract::class, function () { |
|
67
|
6 |
|
return tap(new IndicatorManager, function ($manager) { |
|
68
|
6 |
|
$this->registerIndicators($manager); |
|
69
|
6 |
|
}); |
|
70
|
10 |
|
}); |
|
71
|
|
|
|
|
72
|
10 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Register the indicators. |
|
77
|
|
|
* |
|
78
|
|
|
* @param IndicatorManagerContract $manager |
|
79
|
|
|
*/ |
|
80
|
6 |
|
protected function registerIndicators(IndicatorManagerContract $manager) |
|
81
|
|
|
{ |
|
82
|
6 |
|
foreach (config('indicators') as $shortcut => $indicator) { |
|
83
|
6 |
|
$manager->extend($shortcut, function () use ($indicator) { |
|
84
|
2 |
|
return new $indicator; |
|
85
|
6 |
|
}); |
|
86
|
|
|
} |
|
87
|
6 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the services provided by the provider. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
2 |
|
public function provides() |
|
95
|
|
|
{ |
|
96
|
|
|
return [ |
|
97
|
2 |
|
IndicatorManagerContract::class, |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|