1 | <?php namespace Arcanedev\Agent; |
||
14 | class Agent extends Mobile_Detect implements AgentContract |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * List of desktop devices. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected static $additionalDevices = [ |
||
27 | 'Macintosh' => 'Macintosh', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * List of additional operating systems. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected static $additionalOperatingSystems = [ |
||
36 | 'Windows' => 'Windows', |
||
37 | 'Windows NT' => 'Windows NT', |
||
38 | 'OS X' => 'Mac OS X', |
||
39 | 'Debian' => 'Debian', |
||
40 | 'Ubuntu' => 'Ubuntu', |
||
41 | 'Macintosh' => 'PPC', |
||
42 | 'OpenBSD' => 'OpenBSD', |
||
43 | 'Linux' => 'Linux', |
||
44 | 'ChromeOS' => 'CrOS', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * List of additional browsers. |
||
49 | * Note: 'Vivaldi' must be above Chrome, otherwise it'll fail. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected static $additionalBrowsers = [ |
||
54 | 'Opera' => 'Opera|OPR', |
||
55 | 'Edge' => 'Edge', |
||
56 | 'Vivaldi' => 'Vivaldi', |
||
57 | 'Chrome' => 'Chrome', |
||
58 | 'Firefox' => 'Firefox', |
||
59 | 'Safari' => 'Safari', |
||
60 | 'IE' => 'MSIE|IEMobile|MSIEMobile|Trident/[.0-9]+', |
||
61 | 'Netscape' => 'Netscape', |
||
62 | 'Mozilla' => 'Mozilla', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * List of additional properties. |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | protected static $additionalProperties = [ |
||
71 | // Operating systems |
||
72 | 'Windows' => 'Windows NT [VER]', |
||
73 | 'Windows NT' => 'Windows NT [VER]', |
||
74 | 'OS X' => 'OS X [VER]', |
||
75 | 'BlackBerryOS' => ['BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'], |
||
76 | 'AndroidOS' => 'Android [VER]', |
||
77 | 'ChromeOS' => 'CrOS x86_64 [VER]', |
||
78 | |||
79 | // Browsers |
||
80 | 'Opera' => [' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]', 'Opera [VER]'], |
||
81 | 'Netscape' => 'Netscape/[VER]', |
||
82 | 'Mozilla' => 'rv:[VER]', |
||
83 | 'IE' => ['IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'rv:[VER]'], |
||
84 | 'Edge' => 'Edge/[VER]', |
||
85 | 'Vivaldi' => 'Vivaldi/[VER]', |
||
86 | ]; |
||
87 | |||
88 | /** |
||
89 | * Crawler detector instance. |
||
90 | * |
||
91 | * @var \Arcanedev\Agent\Detectors\CrawlerDetector |
||
92 | */ |
||
93 | protected static $crawlerDetector; |
||
94 | |||
95 | /* ----------------------------------------------------------------- |
||
96 | | Getters & Setters |
||
97 | | ----------------------------------------------------------------- |
||
98 | */ |
||
99 | |||
100 | /** |
||
101 | * Get the crawler detector. |
||
102 | * |
||
103 | * @return \Arcanedev\Agent\Detectors\CrawlerDetector |
||
104 | */ |
||
105 | 27 | public function getCrawlerDetector() |
|
113 | |||
114 | /** |
||
115 | * Get all detection rules. These rules include the additional |
||
116 | * platforms and browsers. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 60 | public function getDetectionRulesExtended() |
|
139 | |||
140 | /** |
||
141 | * Retrieve the current set of rules. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 81 | public function getRules() |
|
151 | |||
152 | /** |
||
153 | * Get the device name. |
||
154 | * |
||
155 | * @param string|null $userAgent |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 6 | public function device($userAgent = null) |
|
171 | |||
172 | /** |
||
173 | * Get the browser name. |
||
174 | * |
||
175 | * @param string|null $userAgent |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | 36 | public function browser($userAgent = null) |
|
189 | |||
190 | /** |
||
191 | * Get the robot name. |
||
192 | * |
||
193 | * @param string|null $userAgent |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | 15 | public function robot($userAgent = null) |
|
203 | |||
204 | /** |
||
205 | * Get the platform name. |
||
206 | * |
||
207 | * @param string|null $userAgent |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | 24 | public function platform($userAgent = null) |
|
221 | |||
222 | /** |
||
223 | * Get the languages. |
||
224 | * |
||
225 | * @param string|null $acceptLanguage |
||
226 | * |
||
227 | * @return array |
||
228 | */ |
||
229 | 6 | public function languages($acceptLanguage = null) |
|
254 | |||
255 | /** |
||
256 | * Match a detection rule and return the matched key. |
||
257 | * |
||
258 | * @param array $rules |
||
259 | * @param null $userAgent |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | 66 | protected function findDetectionRulesAgainstUA(array $rules, $userAgent = null) |
|
274 | |||
275 | /* ----------------------------------------------------------------- |
||
276 | | Main Methods |
||
277 | | ----------------------------------------------------------------- |
||
278 | */ |
||
279 | |||
280 | /** |
||
281 | * Check the version of the given property in the User-Agent. |
||
282 | * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31) |
||
283 | * |
||
284 | * @param string $propertyName The name of the property. See self::getProperties() array |
||
285 | * keys for all possible properties. |
||
286 | * @param string $type Either self::VERSION_TYPE_STRING to get a string value or |
||
287 | * self::VERSION_TYPE_FLOAT indicating a float value. This parameter is optional |
||
288 | * and defaults to self::VERSION_TYPE_STRING. Passing an invalid parameter will |
||
289 | * default to the this type as well. |
||
290 | * |
||
291 | * @return string|float The version of the property we are trying to extract. |
||
292 | */ |
||
293 | 6 | public function version($propertyName, $type = self::VERSION_TYPE_STRING) |
|
308 | |||
309 | /* ----------------------------------------------------------------- |
||
310 | | Check Methods |
||
311 | | ----------------------------------------------------------------- |
||
312 | */ |
||
313 | |||
314 | /** |
||
315 | * Check if the device is a desktop computer. |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | 27 | public function isDesktop() |
|
323 | |||
324 | /** |
||
325 | * Check if device is a robot. |
||
326 | * |
||
327 | * @param string|null $userAgent |
||
328 | * |
||
329 | * @return bool |
||
330 | */ |
||
331 | 27 | public function isRobot($userAgent = null) |
|
335 | |||
336 | /** |
||
337 | * Check if the device is a mobile phone. |
||
338 | * |
||
339 | * @return bool |
||
340 | */ |
||
341 | 24 | public function isPhone() |
|
345 | |||
346 | /* ----------------------------------------------------------------- |
||
347 | | Other Methods |
||
348 | | ----------------------------------------------------------------- |
||
349 | */ |
||
350 | |||
351 | /** |
||
352 | * Merge multiple rules into one array. |
||
353 | * |
||
354 | * @param array $rulesGroups |
||
355 | * |
||
356 | * @return array |
||
357 | */ |
||
358 | 66 | protected function mergeRules(...$rulesGroups) |
|
375 | |||
376 | /** |
||
377 | * Changing detection type to extended. |
||
378 | * |
||
379 | * @inherit |
||
380 | * |
||
381 | * @param string $name |
||
382 | * @param array $arguments |
||
383 | * |
||
384 | * @return bool|mixed |
||
385 | */ |
||
386 | 60 | public function __call($name, $arguments) |
|
397 | } |
||
398 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.