1 | <?php |
||
16 | class PiwikDeviceDetector extends AbstractProvider |
||
17 | { |
||
18 | /** |
||
19 | * Name of the provider |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $name = 'PiwikDeviceDetector'; |
||
24 | |||
25 | /** |
||
26 | * Homepage of the provider |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $homepage = 'https://github.com/piwik/device-detector'; |
||
31 | |||
32 | /** |
||
33 | * Composer package name |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $packageName = 'piwik/device-detector'; |
||
38 | |||
39 | protected $detectionCapabilities = [ |
||
40 | |||
41 | 'browser' => [ |
||
42 | 'name' => true, |
||
43 | 'version' => true, |
||
44 | ], |
||
45 | |||
46 | 'renderingEngine' => [ |
||
47 | 'name' => true, |
||
48 | 'version' => false, |
||
49 | ], |
||
50 | |||
51 | 'operatingSystem' => [ |
||
52 | 'name' => true, |
||
53 | 'version' => true, |
||
54 | ], |
||
55 | |||
56 | 'device' => [ |
||
57 | 'model' => true, |
||
58 | 'brand' => true, |
||
59 | 'type' => true, |
||
60 | 'isMobile' => true, |
||
61 | 'isTouch' => true, |
||
62 | ], |
||
63 | |||
64 | 'bot' => [ |
||
65 | 'isBot' => true, |
||
66 | 'name' => true, |
||
67 | 'type' => true, |
||
68 | ], |
||
69 | ]; |
||
70 | |||
71 | protected $defaultValues = [ |
||
72 | |||
73 | 'general' => [ |
||
74 | '/^UNK$/i', |
||
75 | ], |
||
76 | |||
77 | 'bot' => [ |
||
78 | 'name' => [ |
||
79 | '/^Bot$/i', |
||
80 | '/^Generic Bot$/i', |
||
81 | ], |
||
82 | ], |
||
83 | ]; |
||
84 | |||
85 | /** |
||
86 | * |
||
87 | * @var DeviceDetector |
||
88 | */ |
||
89 | private $parser; |
||
90 | |||
91 | /** |
||
92 | * |
||
93 | * @param DeviceDetector $parser |
||
94 | * @throws PackageNotLoadedException |
||
95 | */ |
||
96 | 17 | public function __construct(DeviceDetector $parser = null) |
|
104 | |||
105 | /** |
||
106 | * |
||
107 | * @return DeviceDetector |
||
108 | */ |
||
109 | 9 | public function getParser() |
|
119 | |||
120 | /** |
||
121 | * |
||
122 | * @param DeviceDetector $dd |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 6 | private function getResultRaw(DeviceDetector $dd) |
|
176 | |||
177 | /** |
||
178 | * |
||
179 | * @param DeviceDetector $dd |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | 8 | private function hasResult(DeviceDetector $dd) |
|
205 | |||
206 | /** |
||
207 | * |
||
208 | * @param Model\Bot $bot |
||
209 | * @param array|boolean $botRaw |
||
210 | */ |
||
211 | 3 | private function hydrateBot(Model\Bot $bot, $botRaw) |
|
222 | |||
223 | /** |
||
224 | * |
||
225 | * @param Model\Browser $browser |
||
226 | * @param array|string $clientRaw |
||
227 | */ |
||
228 | 3 | private function hydrateBrowser(Model\Browser $browser, $clientRaw) |
|
238 | |||
239 | /** |
||
240 | * |
||
241 | * @param Model\RenderingEngine $engine |
||
242 | * @param array|string $clientRaw |
||
243 | */ |
||
244 | 3 | private function hydrateRenderingEngine(Model\RenderingEngine $engine, $clientRaw) |
|
250 | |||
251 | /** |
||
252 | * |
||
253 | * @param Model\OperatingSystem $os |
||
254 | * @param array|string $osRaw |
||
255 | */ |
||
256 | 3 | private function hydrateOperatingSystem(Model\OperatingSystem $os, $osRaw) |
|
266 | |||
267 | /** |
||
268 | * |
||
269 | * @param Model\UserAgent $device |
||
270 | * @param DeviceDetector $dd |
||
271 | */ |
||
272 | 3 | private function hydrateDevice(Model\Device $device, DeviceDetector $dd) |
|
286 | |||
287 | 8 | public function parse($userAgent, array $headers = []) |
|
326 | } |
||
327 |