GelfSupportServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace RenePardon\GelfSupport;
4
5
use Gelf\Publisher;
6
use Gelf\Transport\UdpTransport;
7
use Illuminate\Config\Repository;
8
use Illuminate\Contracts\Debug\ExceptionHandler;
9
use Illuminate\Support\ServiceProvider;
10
use RenePardon\GelfSupport\Commands\TestLogging;
11
12
/**
13
 * Class GelfSupportServiceProvider
14
 *
15
 * @package renepardon\GelfSupport
16
 */
17
class GelfSupportServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $commands = [
23
        TestLogging::class,
24
    ];
25
26
    /**
27
     * Perform post-registration booting of services.
28
     *
29
     * @return void
30
     */
31
    public function boot()
32
    {
33
        $this->publishes([
34
            __DIR__ . '/../config/gelfsupport.php' => config_path('gelfsupport.php'),
35
        ], 'config');
36
    }
37
38
    /**
39
     * Register any package services.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $config = $this->app->make(Repository::class);
46
47
        $this->commands($this->commands);
48
49
        $this->app->alias(ExceptionHandler::class, 'exceptions');
50
        $this->app->singleton('exceptions.repository', ExceptionHandlerRepository::class);
51
        $this->app->extend(ExceptionHandler::class, function ($handler, $app) use ($config) {
52
            return new Decorator($handler, $app['exceptions.repository'], $config);
53
        });
54
55
        $this->app->singleton(Graylog::class, function ($app) use ($config) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
            $transport = new UdpTransport(
57
                $config->get('gelfsupport.host'),
58
                $config->get('gelfsupport.port'),
59
                UdpTransport::CHUNK_SIZE_LAN
60
            );
61
62
            // While the UDP transport is itself a publisher, we wrap it in a real Publisher for convenience.
63
            // A publisher allows for message validation before transmission, and also supports sending
64
            // messages to multiple backends at once.
65
            $publisher = new Publisher();
66
            $publisher->addTransport($transport);
67
68
            return new Graylog($publisher, 'gelf-php');
69
        });
70
    }
71
}
72