1 | <?php |
||||
2 | |||||
3 | namespace ChaseConey\LaravelDatadogHelper; |
||||
4 | |||||
5 | use ChaseConey\LaravelDatadogHelper\Datadog\BatchedDogStatsd; |
||||
6 | use ChaseConey\LaravelDatadogHelper\Datadog\DogStatsd; |
||||
7 | use Illuminate\Support\ServiceProvider; |
||||
8 | |||||
9 | class LaravelDatadogHelperServiceProvider extends ServiceProvider |
||||
10 | { |
||||
11 | |||||
12 | /** |
||||
13 | * Perform post-registration booting of services. |
||||
14 | * |
||||
15 | * @return void |
||||
16 | */ |
||||
17 | public function boot() |
||||
18 | { |
||||
19 | /** @noinspection PhpUndefinedFunctionInspection */ |
||||
20 | $this->publishes( |
||||
21 | [ |
||||
22 | __DIR__ . '/../config/datadog-helper.php' => config_path('datadog-helper.php'), |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
23 | ] |
||||
24 | ); |
||||
25 | } |
||||
26 | |||||
27 | /** |
||||
28 | * Register any package services. |
||||
29 | * |
||||
30 | * @return void |
||||
31 | */ |
||||
32 | public function register() |
||||
33 | { |
||||
34 | $this->app->singleton('datadog', function () { |
||||
35 | return $this->initDatadog(); |
||||
36 | }); |
||||
37 | } |
||||
38 | |||||
39 | protected function initDatadog() |
||||
40 | { |
||||
41 | $this->mergeConfigFrom( |
||||
42 | __DIR__ . '/../config/datadog-helper.php', |
||||
43 | 'datadog-helper' |
||||
44 | ); |
||||
45 | |||||
46 | /** @noinspection PhpUndefinedFunctionInspection */ |
||||
47 | $laravelConfig = config('datadog-helper'); |
||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
48 | |||||
49 | $ddConfig = [ |
||||
50 | 'host' => $laravelConfig['statsd_server'], |
||||
51 | 'port' => $laravelConfig['statsd_port'], |
||||
52 | 'socket_path' => $laravelConfig['statsd_socket_path'], |
||||
53 | 'datadog_host' => $laravelConfig['datadog_host'], |
||||
54 | 'api_key' => $laravelConfig['api_key'], |
||||
55 | 'app_key' => $laravelConfig['application_key'], |
||||
56 | 'global_tags' => $laravelConfig['global_tags'], |
||||
57 | ]; |
||||
58 | |||||
59 | $maxBuffer = $laravelConfig['max_buffer_length']; |
||||
60 | if ($maxBuffer > 1) { |
||||
61 | $datadog = new BatchedDogStatsd($ddConfig); |
||||
62 | $datadog::$maxBufferLength = $maxBuffer; |
||||
63 | } else { |
||||
64 | $datadog = new DogStatsd($ddConfig); |
||||
65 | } |
||||
66 | |||||
67 | $datadog->setMetricsPrefix($laravelConfig['prefix']); |
||||
68 | |||||
69 | return $datadog; |
||||
70 | } |
||||
71 | } |
||||
72 |