Passed
Pull Request — master (#41)
by Mike
02:12
created

Service::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
1
<?php namespace GeneaLabs\LaravelMixpanel\Providers;
2
3
use GeneaLabs\LaravelMixpanel\LaravelMixpanel;
4
use GeneaLabs\LaravelMixpanel\Listeners\LaravelMixpanelEventHandler;
5
use GeneaLabs\LaravelMixpanel\Listeners\LaravelMixpanelUserObserver;
6
use GeneaLabs\LaravelMixpanel\Console\Commands\Publish;
7
use GeneaLabs\LaravelMixpanel\Events\MixpanelEvent;
8
use GeneaLabs\LaravelMixpanel\Listeners\MixpanelEvent as MixpanelEventListener;
9
use Illuminate\Contracts\View\View;
10
use Illuminate\HTTP\Request;
11
use Illuminate\Support\ServiceProvider;
12
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
13
14
abstract class Service extends EventServiceProvider
15
{
16
    protected $defer = false;
17
    protected $listen = [
18
        MixpanelEvent::class => [
19
            MixpanelEventListener::class,
20
        ],
21
    ];
22
23
    public function boot()
24
    {
25
        parent::boot();
26
27
        $this->initialize();
28
    }
29
30
    protected function initialize()
31
    {
32
        include __DIR__ . '/../../routes/api.php';
33
34
        $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'genealabs-laravel-mixpanel');
35
        $this->publishes([
36
            __DIR__ . '/../../public' => public_path(),
37
        ], 'assets');
38
39
        if (config('services.mixpanel.enable-default-tracking')) {
40
            $authModel = config('auth.providers.users.model') ?? config('auth.model');
41
            $this->app->make($authModel)->observe(new LaravelMixpanelUserObserver());
42
            app('events')->subscribe(new LaravelMixpanelEventHandler());
43
        }
44
    }
45
46
    public function register()
47
    {
48
        $this->mergeConfigFrom(__DIR__ . '/../../config/services.php', 'services');
49
        $this->commands(Publish::class);
50
        $this->app->singleton('mixpanel', LaravelMixpanel::class);
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function provides()
57
    {
58
        return ['genealabs-laravel-mixpanel'];
59
    }
60
}
61