Completed
Push — master ( c4d057...a4831f )
by ARCANEDEV
07:52
created

LaravelTrackerServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
ccs 5
cts 5
cp 1
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\LaravelTracker;
2
3
use Arcanedev\Support\PackageServiceProvider;
4
5
/**
6
 * Class     LaravelTrackerServiceProvider
7
 *
8
 * @package  Arcanedev\LaravelTracker
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class LaravelTrackerServiceProvider extends PackageServiceProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Package name.
19
     *
20
     * @var string
21
     */
22
    protected $package = 'laravel-tracker';
23
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Getters & Setters
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    /**
29
     * Get the base path of the package.
30
     *
31
     * @return string
32
     */
33 48
    public function getBasePath()
34
    {
35 48
        return dirname(__DIR__);
36
    }
37
38
    /* ------------------------------------------------------------------------------------------------
39
     |  Main Functions
40
     | ------------------------------------------------------------------------------------------------
41
     */
42
    /**
43
     * Register the service provider.
44
     */
45 48
    public function register()
46
    {
47 48
        $this->registerConfig();
48
49 48
        $this->app->register(Providers\PackagesServiceProvider::class);
50
51 48
        if ($this->app->runningInConsole())
52 48
            $this->app->register(Providers\CommandServiceProvider::class);
53
54 48
        $this->registerDetectors();
55 48
        $this->registerParsers();
56 48
        $this->registerTracker();
57 48
    }
58
59
    /**
60
     * Boot the service provider.
61
     */
62 48
    public function boot()
63
    {
64 48
        parent::boot();
65
66 48
        $this->publishConfig();
67 48
        $this->publishMigrations();
68 48
    }
69
70
    /**
71
     * Get the services provided by the provider.
72
     *
73
     * @return array
74
     */
75 6
    public function provides()
76
    {
77
        return [
78 6
            'arcanedev.tracker',
79 3
            Contracts\Tracker::class,
80 3
        ];
81
    }
82
83
    /* ------------------------------------------------------------------------------------------------
84
     |  Other Functions
85
     | ------------------------------------------------------------------------------------------------
86
     */
87
    /**
88
     * Register the detectors.
89
     */
90 48
    private function registerDetectors()
91
    {
92
        $this->singleton(Contracts\Detectors\CrawlerDetector::class, function ($app) {
93
            $crawler = new \Jaybizzle\CrawlerDetect\CrawlerDetect(
94
                $app['request']->headers->all(),
95
                $app['request']->server('HTTP_USER_AGENT')
96
            );
97
98
            return new Detectors\CrawlerDetector($crawler);
99 48
        });
100
101
        $this->singleton(Contracts\Detectors\DeviceDetector::class, function ($app) {
102
            return new Detectors\DeviceDetector($app['agent']);
103 48
        });
104
105 48
        $this->singleton(
106 48
            Contracts\Detectors\GeoIpDetector::class,
107 24
            Detectors\GeoIpDetector::class
108 24
        );
109
110
        $this->singleton(Contracts\Detectors\LanguageDetector::class, function ($app) {
111
            return new Detectors\LanguageDetector($app['agent']);
112 48
        });
113
114
        $this->singleton(Contracts\Detectors\UserDetector::class, function ($app) {
115
            return new Detectors\UserDetector($app);
116 48
        });
117 48
    }
118
119
    /**
120
     * Register the parsers.
121
     */
122 48
    private function registerParsers()
123
    {
124
        $this->singleton(Contracts\Parsers\RefererParser::class, function () {
125 6
            return new Parsers\RefererParser(
126 3
                new \Snowplow\RefererParser\Parser
127 3
            );
128 48
        });
129
130 48
        $this->singleton(Contracts\Parsers\UserAgentParser::class, function ($app) {
131
            return new Parsers\UserAgentParser(
132
                \UAParser\Parser::create(),
133
                $app->make('path.base')
134
            );
135 48
        });
136 48
    }
137
138
    /**
139
     * Register the tracker.
140
     */
141 48
    private function registerTracker()
142
    {
143 48
        $this->singleton('arcanedev.tracker', Tracker::class);
144 48
        $this->bind(Contracts\Tracker::class, Tracker::class);
145 48
    }
146
}
147