1 | <?php namespace Arcanedev\LaravelTracker; |
||
13 | class LaravelTrackerServiceProvider extends PackageServiceProvider |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * Package name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $package = 'laravel-tracker'; |
||
26 | |||
27 | /* ----------------------------------------------------------------- |
||
28 | | Main Methods |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | /** |
||
33 | * Register the service provider. |
||
34 | */ |
||
35 | 117 | public function register() |
|
36 | { |
||
37 | 117 | parent::register(); |
|
38 | |||
39 | 117 | $this->registerConfig(); |
|
40 | 117 | $this->registerProviders([ |
|
41 | 117 | Providers\PackagesServiceProvider::class, |
|
42 | Providers\EventServiceProvider::class, |
||
43 | ]); |
||
44 | 117 | $this->registerConsoleServiceProvider(Providers\CommandServiceProvider::class); |
|
45 | |||
46 | 117 | $this->registerDetectors(); |
|
47 | 117 | $this->registerParsers(); |
|
48 | 117 | $this->registerTrackers(); |
|
49 | 117 | $this->registerMainTracker(); |
|
50 | 117 | $this->registerExceptionHandler(); |
|
51 | 117 | } |
|
52 | |||
53 | /** |
||
54 | * Boot the service provider. |
||
55 | */ |
||
56 | 117 | public function boot() |
|
67 | |||
68 | /** |
||
69 | * Get the services provided by the provider. |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | 3 | public function provides() |
|
74 | { |
||
75 | return [ |
||
76 | 3 | Contracts\Tracker::class, |
|
77 | ]; |
||
78 | } |
||
79 | |||
80 | /* ----------------------------------------------------------------- |
||
81 | | Other Methods |
||
82 | | ----------------------------------------------------------------- |
||
83 | */ |
||
84 | /** |
||
85 | * Binding the models with the contracts. |
||
86 | */ |
||
87 | 117 | private function registerModelsBindings() |
|
88 | { |
||
89 | 117 | foreach (Support\BindingManager::getModelsBindings() as $key => $contract) { |
|
90 | 117 | $this->bind($contract, $this->config()->get("laravel-tracker.models.$key")); |
|
91 | } |
||
92 | 117 | } |
|
93 | |||
94 | /** |
||
95 | * Register the detectors. |
||
96 | */ |
||
97 | private function registerDetectors() |
||
98 | { |
||
99 | 117 | $this->singleton(Contracts\Detectors\CrawlerDetector::class, function (AppContract $app) { |
|
100 | /** @var \Illuminate\Http\Request $request */ |
||
101 | 6 | $request = $app['request']; |
|
102 | |||
103 | 6 | return new Detectors\CrawlerDetector( |
|
104 | 6 | new \Jaybizzle\CrawlerDetect\CrawlerDetect( |
|
105 | 6 | $request->headers->all(), |
|
106 | 6 | $request->server('HTTP_USER_AGENT') |
|
107 | ) |
||
108 | ); |
||
109 | 117 | }); |
|
110 | |||
111 | 117 | $this->singleton(Contracts\Detectors\DeviceDetector::class, Detectors\DeviceDetector::class); |
|
112 | 117 | $this->singleton(Contracts\Detectors\GeoIpDetector::class, Detectors\GeoIpDetector::class); |
|
113 | 117 | $this->singleton(Contracts\Detectors\LanguageDetector::class, Detectors\LanguageDetector::class); |
|
114 | 117 | } |
|
115 | |||
116 | /** |
||
117 | * Register the parsers. |
||
118 | */ |
||
119 | private function registerParsers() |
||
120 | { |
||
121 | 117 | $this->singleton(Contracts\Parsers\RefererParser::class, function () { |
|
122 | 9 | return new Parsers\RefererParser( |
|
123 | 9 | new \Snowplow\RefererParser\Parser |
|
124 | ); |
||
125 | 117 | }); |
|
126 | |||
127 | 117 | $this->singleton(Contracts\Parsers\UserAgentParser::class, function (AppContract $app) { |
|
128 | 15 | return new Parsers\UserAgentParser( |
|
129 | 15 | \UAParser\Parser::create(), $app->make('path.base') |
|
130 | ); |
||
131 | 117 | }); |
|
132 | 117 | } |
|
133 | |||
134 | /** |
||
135 | * Register the trackers. |
||
136 | */ |
||
137 | 117 | private function registerTrackers() |
|
138 | { |
||
139 | 117 | foreach (Support\BindingManager::getTrackersBindings() as $abstract => $concrete) { |
|
140 | 117 | $this->singleton($abstract, $concrete); |
|
141 | } |
||
142 | 117 | } |
|
143 | |||
144 | /** |
||
145 | * Register the main tracker. |
||
146 | */ |
||
147 | 117 | private function registerMainTracker() |
|
151 | |||
152 | /** |
||
153 | * Register the exception handler. |
||
154 | */ |
||
155 | 117 | private function registerExceptionHandler() |
|
163 | } |
||
164 |