1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Serhii Nekhaienko <[email protected]> |
4
|
|
|
* @license GPL |
5
|
|
|
* @copyright Serhii Nekhaienko © 2018 |
6
|
|
|
* @version 4.0.0 |
7
|
|
|
* @project endorphin-studio/browser-detector |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace EndorphinStudio\Detector\Data; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Result |
14
|
|
|
* Class with result of detection |
15
|
|
|
* @package EndorphinStudio\Detector\Data |
16
|
|
|
*/ |
17
|
|
|
class Result implements \JsonSerializable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Get User Agent |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
public function getUserAgent(): string |
24
|
|
|
{ |
25
|
|
|
return $this->userAgent; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** @var string UserAgent */ |
29
|
|
|
protected $userAgent = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Os Result of os detection |
33
|
|
|
*/ |
34
|
|
|
protected $os; |
35
|
|
|
/** |
36
|
|
|
* @var Browser Result of browser detection |
37
|
|
|
*/ |
38
|
|
|
protected $browser; |
39
|
|
|
/** |
40
|
|
|
* @var Device Result of device detection |
41
|
|
|
*/ |
42
|
|
|
protected $device; |
43
|
|
|
/** |
44
|
|
|
* @var Robot Result of robot detection |
45
|
|
|
*/ |
46
|
|
|
protected $robot; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var boolean true if user is robot |
50
|
|
|
*/ |
51
|
|
|
protected $isRobot = false; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var boolean true if device is touch |
55
|
|
|
*/ |
56
|
|
|
protected $isTouch = false; |
57
|
|
|
/** |
58
|
|
|
* @var boolean true if device is mobile |
59
|
|
|
*/ |
60
|
|
|
protected $isMobile = false; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* True if user is robot |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function isRobot(): bool |
67
|
|
|
{ |
68
|
|
|
return $this->isRobot; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Setter |
73
|
|
|
* @param bool $isRobot |
74
|
|
|
*/ |
75
|
|
|
public function setIsRobot(bool $isRobot) |
76
|
|
|
{ |
77
|
|
|
$this->isRobot = $isRobot; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* True if user is touch |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function isTouch(): bool |
85
|
|
|
{ |
86
|
|
|
return $this->isTouch; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Setter |
91
|
|
|
* @param bool $isTouch |
92
|
|
|
*/ |
93
|
|
|
public function setIsTouch(bool $isTouch) |
94
|
|
|
{ |
95
|
|
|
$this->isTouch = $isTouch; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* True if user is mobile |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
public function isMobile(): bool |
103
|
|
|
{ |
104
|
|
|
return $this->isMobile; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Setter |
109
|
|
|
* @param bool $isMobile |
110
|
|
|
*/ |
111
|
|
|
public function setIsMobile(bool $isMobile) |
112
|
|
|
{ |
113
|
|
|
$this->isMobile = $isMobile; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* True if user is tablet |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function isTablet(): bool |
121
|
|
|
{ |
122
|
|
|
return $this->isTablet; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Setter |
127
|
|
|
* @param bool $isTablet |
128
|
|
|
*/ |
129
|
|
|
public function setIsTablet(bool $isTablet) |
130
|
|
|
{ |
131
|
|
|
$this->isTablet = $isTablet; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** @var boolean true if user is tablet */ |
135
|
|
|
protected $isTablet = false; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Result constructor. |
139
|
|
|
* @param string $userAgent User Agent |
140
|
|
|
*/ |
141
|
|
|
public function __construct(string $userAgent) |
142
|
|
|
{ |
143
|
|
|
$this->os = new Os($this); |
144
|
|
|
$this->device = new Device($this); |
145
|
|
|
$this->browser = new Browser($this); |
146
|
|
|
$this->robot = new Robot($this); |
147
|
|
|
$this->userAgent = $userAgent; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get result of os detection |
152
|
|
|
* @return Os |
153
|
|
|
*/ |
154
|
|
|
public function getOs(): Os |
155
|
|
|
{ |
156
|
|
|
return $this->os; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get result of browser detection |
161
|
|
|
* @return Browser |
162
|
|
|
*/ |
163
|
|
|
public function getBrowser(): Browser |
164
|
|
|
{ |
165
|
|
|
return $this->browser; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get result of device detection |
170
|
|
|
* @return Device |
171
|
|
|
*/ |
172
|
|
|
public function getDevice(): Device |
173
|
|
|
{ |
174
|
|
|
return $this->device; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get result of robot detection |
179
|
|
|
* @return Robot |
180
|
|
|
*/ |
181
|
|
|
public function getRobot(): Robot |
182
|
|
|
{ |
183
|
|
|
return $this->robot; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function jsonSerialize() |
187
|
|
|
{ |
188
|
|
|
return get_object_vars($this); |
189
|
|
|
} |
190
|
|
|
} |