|
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
|
|
|
$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
|
|
|
$this->singleton(Contracts\Trackers\CookieTracker::class, function () { |
|
145
|
24 |
|
return new Trackers\CookieTracker; |
|
146
|
48 |
|
}); |
|
147
|
|
|
|
|
148
|
|
|
$this->singleton(Contracts\Trackers\DeviceTracker::class, function ($app) { |
|
149
|
24 |
|
return new Trackers\DeviceTracker( |
|
150
|
24 |
|
$app[Contracts\Detectors\DeviceDetector::class], |
|
151
|
24 |
|
$app[Contracts\Parsers\UserAgentParser::class] |
|
152
|
12 |
|
); |
|
153
|
48 |
|
}); |
|
154
|
|
|
|
|
155
|
|
|
$this->singleton(Contracts\Trackers\GeoIpTracker::class, function ($app) { |
|
156
|
24 |
|
return new Trackers\GeoIpTracker( |
|
157
|
24 |
|
$app[Contracts\Detectors\GeoIpDetector::class] |
|
158
|
12 |
|
); |
|
159
|
48 |
|
}); |
|
160
|
|
|
|
|
161
|
|
|
$this->singleton(Contracts\Trackers\LanguageTracker::class, function ($app) { |
|
162
|
24 |
|
return new Trackers\LanguageTracker( |
|
163
|
24 |
|
$app[Contracts\Detectors\LanguageDetector::class] |
|
164
|
12 |
|
); |
|
165
|
48 |
|
}); |
|
166
|
|
|
|
|
167
|
|
|
$this->singleton(Contracts\Trackers\RefererTracker::class, function ($app) { |
|
168
|
24 |
|
return new Trackers\RefererTracker( |
|
169
|
24 |
|
$app[Contracts\Parsers\RefererParser::class] |
|
170
|
12 |
|
); |
|
171
|
48 |
|
}); |
|
172
|
|
|
|
|
173
|
|
|
$this->singleton(Contracts\Trackers\SessionTracker::class, function () { |
|
174
|
24 |
|
return new Trackers\SessionTracker; |
|
175
|
48 |
|
}); |
|
176
|
|
|
|
|
177
|
|
|
$this->singleton(Contracts\Trackers\UserAgentTracker::class, function ($app) { |
|
178
|
24 |
|
return new Trackers\UserAgentTracker( |
|
179
|
24 |
|
$app[Contracts\Parsers\UserAgentParser::class] |
|
180
|
12 |
|
); |
|
181
|
48 |
|
}); |
|
182
|
|
|
|
|
183
|
48 |
|
$this->singleton(Contracts\Trackers\UserTracker::class, function ($app) { |
|
184
|
24 |
|
return new Trackers\UserTracker($app); |
|
185
|
48 |
|
}); |
|
186
|
|
|
|
|
187
|
|
|
// Register the trackers manager |
|
188
|
48 |
|
$this->singleton(Contracts\TrackingManager::class, TrackingManager::class); |
|
189
|
48 |
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Register the main tracker. |
|
193
|
|
|
*/ |
|
194
|
48 |
|
private function registerMainTracker() |
|
195
|
|
|
{ |
|
196
|
48 |
|
$this->singleton('arcanedev.tracker', Tracker::class); |
|
197
|
48 |
|
$this->bind(Contracts\Tracker::class, Tracker::class); |
|
198
|
48 |
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|