1 | <?php |
||
16 | class Zsxsoft extends AbstractProvider |
||
17 | { |
||
18 | /** |
||
19 | * Name of the provider |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $name = 'Zsxsoft'; |
||
24 | |||
25 | /** |
||
26 | * Homepage of the provider |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $homepage = 'https://github.com/zsxsoft/php-useragent'; |
||
31 | |||
32 | /** |
||
33 | * Composer package name |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $packageName = 'zsxsoft/php-useragent'; |
||
38 | |||
39 | protected $detectionCapabilities = [ |
||
40 | |||
41 | 'browser' => [ |
||
42 | 'name' => true, |
||
43 | 'version' => true, |
||
44 | ], |
||
45 | |||
46 | 'renderingEngine' => [ |
||
47 | 'name' => false, |
||
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' => false, |
||
60 | 'isMobile' => false, |
||
61 | 'isTouch' => false, |
||
62 | ], |
||
63 | |||
64 | 'bot' => [ |
||
65 | 'isBot' => false, |
||
66 | 'name' => false, |
||
67 | 'type' => false, |
||
68 | ], |
||
69 | ]; |
||
70 | |||
71 | protected $defaultValues = [ |
||
72 | |||
73 | 'general' => [ |
||
74 | '/^Unknown$/i', |
||
75 | ], |
||
76 | |||
77 | 'browser' => [ |
||
78 | 'name' => [ |
||
79 | '/^Mozilla Compatible$/i', |
||
80 | ], |
||
81 | ], |
||
82 | |||
83 | 'device' => [ |
||
84 | 'model' => [ |
||
85 | '/^Browser$/i', |
||
86 | '/^Android$/i', |
||
87 | ], |
||
88 | ], |
||
89 | ]; |
||
90 | |||
91 | private $parser; |
||
92 | |||
93 | /** |
||
94 | * |
||
95 | * @param UserAgent $parser |
||
96 | * @throws PackageNotLoadedException |
||
97 | */ |
||
98 | 16 | public function __construct(UserAgent $parser = null) |
|
106 | |||
107 | /** |
||
108 | * |
||
109 | * @return UserAgent |
||
110 | */ |
||
111 | 8 | public function getParser() |
|
121 | |||
122 | /** |
||
123 | * |
||
124 | * @param array $browser |
||
125 | * @param array $os |
||
126 | * @param array $device |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | 7 | private function hasResult(array $browser, array $os, array $device) |
|
150 | |||
151 | /** |
||
152 | * |
||
153 | * @param Model\Browser $browser |
||
154 | * @param array $browserRaw |
||
155 | */ |
||
156 | 4 | private function hydrateBrowser(Model\Browser $browser, array $browserRaw) |
|
157 | { |
||
158 | 4 | if (isset($browserRaw['name'])) { |
|
159 | 1 | $browser->setName($this->getRealResult($browserRaw['name'], 'browser', 'name')); |
|
160 | } |
||
161 | |||
162 | 4 | if (isset($browserRaw['version'])) { |
|
163 | 1 | $browser->getVersion()->setComplete($this->getRealResult($browserRaw['version'])); |
|
164 | } |
||
165 | 4 | } |
|
166 | |||
167 | /** |
||
168 | * |
||
169 | * @param Model\OperatingSystem $os |
||
170 | * @param array $osRaw |
||
171 | */ |
||
172 | 4 | private function hydrateOperatingSystem(Model\OperatingSystem $os, array $osRaw) |
|
173 | { |
||
174 | 4 | if (isset($osRaw['name'])) { |
|
175 | 1 | $os->setName($this->getRealResult($osRaw['name'])); |
|
176 | } |
||
177 | |||
178 | 4 | if (isset($osRaw['version'])) { |
|
179 | 1 | $os->getVersion()->setComplete($this->getRealResult($osRaw['version'])); |
|
180 | } |
||
181 | 4 | } |
|
182 | |||
183 | /** |
||
184 | * |
||
185 | * @param Model\Device $device |
||
186 | * @param array $deviceRaw |
||
187 | */ |
||
188 | 4 | private function hydrateDevice(Model\Device $device, array $deviceRaw) |
|
189 | { |
||
190 | 4 | if (isset($deviceRaw['model'])) { |
|
191 | 2 | $device->setModel($this->getRealResult($deviceRaw['model'], 'device', 'model')); |
|
192 | } |
||
193 | |||
194 | 4 | if (isset($deviceRaw['brand'])) { |
|
195 | 1 | $device->setBrand($this->getRealResult($deviceRaw['brand'])); |
|
196 | } |
||
197 | 4 | } |
|
198 | |||
199 | 7 | public function parse($userAgent, array $headers = []) |
|
236 | } |
||
237 |