1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ErsoyInsider\NewrelicCustomEvent; |
4
|
|
|
|
5
|
|
|
use ErsoyInsider\NewrelicCustomEvent\Models\NewRelicConfig; |
6
|
|
|
use ErsoyInsider\NewrelicCustomEvent\Services\NewRelicDispatcher; |
7
|
|
|
use ErsoyInsider\NewrelicCustomEvent\Services\NewRelicPostService; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use Ixudra\Curl\CurlService; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ServiceProviderTest |
13
|
|
|
* @package ErsoyInsider\NewRelicCustomEvent |
14
|
|
|
*/ |
15
|
|
|
class NewRelicCustomEventServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Indicates if loading of the provider is deferred. |
19
|
|
|
* |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $defer = false; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The subscriber classes to register. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $listens = [ |
30
|
|
|
'ErsoyInsider\NewrelicCustomEvent\Events\CustomEvent' => [ |
31
|
|
|
'ErsoyInsider\NewrelicCustomEvent\Listeners\CaptureCustomEvent' |
32
|
|
|
] |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function boot() |
39
|
|
|
{ |
40
|
|
|
$this->setUpListeners(); |
41
|
|
|
$this->setUpConfig(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function setUpListeners() |
45
|
|
|
{ |
46
|
|
|
foreach ($this->listens as $event => $listeners) { |
47
|
|
|
foreach ($listeners as $listener) { |
48
|
|
|
$this->app['events']->listen($event, $listener); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function setUpConfig() |
54
|
|
|
{ |
55
|
|
|
$source = dirname(__DIR__) . '/config/new-relic-custom-event.php'; |
56
|
|
|
$this->app->configure('new-relic-custom-event'); |
57
|
|
|
$this->mergeConfigFrom($source, 'new-relic-custom-event'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function register() |
61
|
|
|
{ |
62
|
|
|
$this->app->singleton('new-relic-custom-event', function ($app) { |
63
|
|
|
return new NewRelicPostService( |
64
|
|
|
new NewRelicConfig( |
65
|
|
|
$app['config']['new-relic-custom-event.account_id'], |
66
|
|
|
$app['config']['new-relic-custom-event.api_key'] |
67
|
|
|
), |
68
|
|
|
new CurlService() |
69
|
|
|
); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->app->singleton('new-relic-dispatcher', function ($app) { |
74
|
|
|
return new NewRelicDispatcher($app['config'], $app['events']); |
75
|
|
|
}); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function provides() |
82
|
|
|
{ |
83
|
|
|
return ['new-relic-custom-event', 'new-relic-dispatcher']; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|