Completed
Push — master ( b18803...20db03 )
by ARCANEDEV
09:32
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->registerTrackers();
57 48
        $this->registerMainTracker();
58 48
    }
59
60
    /**
61
     * Boot the service provider.
62
     */
63 48
    public function boot()
64
    {
65 48
        parent::boot();
66
67 48
        $this->publishConfig();
68 48
        $this->publishMigrations();
69 48
    }
70
71
    /**
72
     * Get the services provided by the provider.
73
     *
74
     * @return array
75
     */
76 6
    public function provides()
77
    {
78
        return [
79 6
            'arcanedev.tracker',
80 3
            Contracts\Tracker::class,
81 3
        ];
82
    }
83
84
    /* ------------------------------------------------------------------------------------------------
85
     |  Other Functions
86
     | ------------------------------------------------------------------------------------------------
87
     */
88
    /**
89
     * Register the detectors.
90
     */
91 48
    private function registerDetectors()
92
    {
93
        $this->singleton(Contracts\Detectors\CrawlerDetector::class, function ($app) {
94
            $crawler = new \Jaybizzle\CrawlerDetect\CrawlerDetect(
95
                $app['request']->headers->all(),
96
                $app['request']->server('HTTP_USER_AGENT')
97
            );
98
99
            return new Detectors\CrawlerDetector($crawler);
100 48
        });
101
102
        $this->singleton(Contracts\Detectors\DeviceDetector::class, function ($app) {
103 24
            return new Detectors\DeviceDetector($app['agent']);
104 48
        });
105
106 48
        $this->singleton(
107 48
            Contracts\Detectors\GeoIpDetector::class,
108 24
            Detectors\GeoIpDetector::class
109 24
        );
110
111
        $this->singleton(Contracts\Detectors\LanguageDetector::class, function ($app) {
112 24
            return new Detectors\LanguageDetector($app['agent']);
113 48
        });
114
115
        $this->singleton(Contracts\Detectors\UserDetector::class, function ($app) {
116
            return new Detectors\UserDetector($app);
117 48
        });
118 48
    }
119
120
    /**
121
     * Register the parsers.
122
     */
123 48
    private function registerParsers()
124
    {
125
        $this->singleton(Contracts\Parsers\RefererParser::class, function () {
126 24
            return new Parsers\RefererParser(
127 12
                new \Snowplow\RefererParser\Parser
128 12
            );
129 48
        });
130
131 48
        $this->singleton(Contracts\Parsers\UserAgentParser::class, function ($app) {
132 24
            return new Parsers\UserAgentParser(
133 24
                \UAParser\Parser::create(),
134 24
                $app->make('path.base')
135 12
            );
136 48
        });
137 48
    }
138
139
    /**
140
     * Register the trackers.
141
     */
142 48
    private function registerTrackers()
143
    {
144 48
        $this->singleton(Contracts\Trackers\CookieTracker::class,    Trackers\CookieTracker::class);
145 48
        $this->singleton(Contracts\Trackers\DeviceTracker::class,    Trackers\DeviceTracker::class);
146 48
        $this->singleton(Contracts\Trackers\GeoIpTracker::class,     Trackers\GeoIpTracker::class);
147 48
        $this->singleton(Contracts\Trackers\LanguageTracker::class,  Trackers\LanguageTracker::class);
148 48
        $this->singleton(Contracts\Trackers\RefererTracker::class,   Trackers\RefererTracker::class);
149 48
        $this->singleton(Contracts\Trackers\SessionTracker::class,   Trackers\SessionTracker::class);
150 48
        $this->singleton(Contracts\Trackers\UserAgentTracker::class, Trackers\UserAgentTracker::class);
151 48
        $this->singleton(Contracts\Trackers\UserTracker::class,      Trackers\UserTracker::class);
152
153
        // Register the trackers manager
154 48
        $this->singleton(Contracts\TrackingManager::class, TrackingManager::class);
155 48
    }
156
157
    /**
158
     * Register the main tracker.
159
     */
160 48
    private function registerMainTracker()
161
    {
162 48
        $this->singleton('arcanedev.tracker', Tracker::class);
163 48
        $this->bind(Contracts\Tracker::class, Tracker::class);
164 48
    }
165
}
166