Completed
Push — master ( 20db03...f76772 )
by ARCANEDEV
14:47 queued 07:12
created

LaravelTrackerServiceProvider::getBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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
            /** @var \Illuminate\Http\Request $request */
95
            $request = $app['request'];
96
            $crawler = new \Jaybizzle\CrawlerDetect\CrawlerDetect(
97
                $request->headers->all(),
98
                $request->server('HTTP_USER_AGENT')
99
            );
100
101
            return new Detectors\CrawlerDetector($crawler);
102 48
        });
103
104
        $this->singleton(Contracts\Detectors\DeviceDetector::class, function ($app) {
105 24
            return new Detectors\DeviceDetector($app['agent']);
106 48
        });
107
108 48
        $this->singleton(
109 48
            Contracts\Detectors\GeoIpDetector::class,
110 24
            Detectors\GeoIpDetector::class
111 24
        );
112
113
        $this->singleton(Contracts\Detectors\LanguageDetector::class, function ($app) {
114 24
            return new Detectors\LanguageDetector($app['agent']);
115 48
        });
116 48
    }
117
118
    /**
119
     * Register the parsers.
120
     */
121 48
    private function registerParsers()
122
    {
123
        $this->singleton(Contracts\Parsers\RefererParser::class, function () {
124 24
            return new Parsers\RefererParser(
125 12
                new \Snowplow\RefererParser\Parser
126 12
            );
127 48
        });
128
129 48
        $this->singleton(Contracts\Parsers\UserAgentParser::class, function ($app) {
130 24
            return new Parsers\UserAgentParser(
131 24
                \UAParser\Parser::create(),
132 24
                $app->make('path.base')
133 12
            );
134 48
        });
135 48
    }
136
137
    /**
138
     * Register the trackers.
139
     */
140 48
    private function registerTrackers()
141
    {
142 48
        $this->singleton(Contracts\Trackers\CookieTracker::class,    Trackers\CookieTracker::class);
143 48
        $this->singleton(Contracts\Trackers\DeviceTracker::class,    Trackers\DeviceTracker::class);
144 48
        $this->singleton(Contracts\Trackers\GeoIpTracker::class,     Trackers\GeoIpTracker::class);
145 48
        $this->singleton(Contracts\Trackers\LanguageTracker::class,  Trackers\LanguageTracker::class);
146 48
        $this->singleton(Contracts\Trackers\RefererTracker::class,   Trackers\RefererTracker::class);
147 48
        $this->singleton(Contracts\Trackers\SessionTracker::class,   Trackers\SessionTracker::class);
148 48
        $this->singleton(Contracts\Trackers\UserAgentTracker::class, Trackers\UserAgentTracker::class);
149 48
        $this->singleton(Contracts\Trackers\UserTracker::class,      Trackers\UserTracker::class);
150
151
        // Register the trackers manager
152 48
        $this->singleton(Contracts\TrackingManager::class, TrackingManager::class);
153 48
    }
154
155
    /**
156
     * Register the main tracker.
157
     */
158 48
    private function registerMainTracker()
159
    {
160 48
        $this->singleton('arcanedev.tracker', Tracker::class);
161 48
        $this->bind(Contracts\Tracker::class, Tracker::class);
162 48
    }
163
}
164