1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MobileDetect.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:MobileDetect! |
9
|
|
|
* @subpackage common |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 21.04.14 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\MobileDetect; |
18
|
|
|
|
19
|
|
|
use Nette\Http; |
20
|
|
|
|
21
|
|
|
use IPub\MobileDetect\Helpers; |
22
|
|
|
|
23
|
|
|
use Jenssegers\Agent; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Mobile detect detector service |
27
|
|
|
* |
28
|
|
|
* @package iPublikuj:MobileDetect! |
29
|
|
|
* @subpackage common |
30
|
|
|
* |
31
|
|
|
* @author Adam Kadlec <[email protected]> |
32
|
|
|
*/ |
33
|
1 |
|
final class MobileDetect extends Agent\Agent |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var Helpers\DeviceView |
37
|
|
|
*/ |
38
|
|
|
private $deviceView; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Helpers\DeviceView $deviceView |
42
|
|
|
* @param Http\Request $httpRequest |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
Helpers\DeviceView $deviceView, |
46
|
|
|
Http\Request $httpRequest |
47
|
|
|
) { |
48
|
|
|
// Get http headers |
49
|
1 |
|
$httpHeaders = $httpRequest->getHeaders(); |
50
|
|
|
|
51
|
1 |
|
$userAgent = NULL; |
52
|
|
|
|
53
|
|
|
// If user agent info is set in headers... |
54
|
1 |
|
if (isset($httpHeaders['user-agent'])) { |
55
|
|
|
// ...set user agent details |
56
|
|
|
$userAgent = $httpHeaders['user-agent']; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
parent::__construct($httpHeaders, $userAgent); |
60
|
|
|
|
61
|
1 |
|
$this->deviceView = $deviceView; |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Check if the device is not mobile phone |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function isNotPhone() : bool |
70
|
|
|
{ |
71
|
|
|
return (($this->isMobile() && $this->isTablet()) || !$this->isMobile()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function view() : string |
78
|
|
|
{ |
79
|
|
|
return $this->deviceView->getViewType(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function browserVersion() : string |
86
|
|
|
{ |
87
|
|
|
return (string) $this->version($this->browser()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function platformVersion() : string |
94
|
|
|
{ |
95
|
|
|
return (string) $this->version($this->platform()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|