1 | <?php |
||
15 | abstract class AbstractProvider |
||
16 | { |
||
17 | /** |
||
18 | * Name of the provider |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name; |
||
23 | |||
24 | /** |
||
25 | * Homepage of the provider |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $homepage; |
||
30 | |||
31 | /** |
||
32 | * Composer package name |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $packageName; |
||
37 | |||
38 | /** |
||
39 | * Version string for caching |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $version; |
||
44 | |||
45 | /** |
||
46 | * Last update date |
||
47 | * |
||
48 | * @var DateTime |
||
49 | */ |
||
50 | private $updateDate; |
||
51 | |||
52 | /** |
||
53 | * Per default the provider cannot detect anything |
||
54 | * Activate them in $detectionCapabilities |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $allDetectionCapabilities = [ |
||
59 | 'browser' => [ |
||
60 | 'name' => false, |
||
61 | 'version' => false, |
||
62 | ], |
||
63 | |||
64 | 'renderingEngine' => [ |
||
65 | 'name' => false, |
||
66 | 'version' => false, |
||
67 | ], |
||
68 | |||
69 | 'operatingSystem' => [ |
||
70 | 'name' => false, |
||
71 | 'version' => false, |
||
72 | ], |
||
73 | |||
74 | 'device' => [ |
||
75 | 'model' => false, |
||
76 | 'brand' => false, |
||
77 | 'type' => false, |
||
78 | 'isMobile' => false, |
||
79 | 'isTouch' => false, |
||
80 | ], |
||
81 | |||
82 | 'bot' => [ |
||
83 | 'isBot' => false, |
||
84 | 'name' => false, |
||
85 | 'type' => false, |
||
86 | ], |
||
87 | ]; |
||
88 | |||
89 | /** |
||
90 | * Set this in each Provider implementation |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $detectionCapabilities = []; |
||
95 | |||
96 | protected $defaultValues = [ |
||
97 | 'general' => [], |
||
98 | ]; |
||
99 | |||
100 | /** |
||
101 | * Return the name of the provider |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 1 | public function getName() |
|
109 | |||
110 | /** |
||
111 | * Get the homepage |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 1 | public function getHomepage() |
|
119 | |||
120 | /** |
||
121 | * Get the package name |
||
122 | * |
||
123 | * @return string null |
||
124 | */ |
||
125 | 5 | public function getPackageName() |
|
129 | |||
130 | /** |
||
131 | * Return the version of the provider |
||
132 | * |
||
133 | * @return string null |
||
134 | */ |
||
135 | 2 | public function getVersion() |
|
161 | |||
162 | /** |
||
163 | * Get the last change date of the provider |
||
164 | * |
||
165 | * @return DateTime null |
||
166 | */ |
||
167 | 2 | public function getUpdateDate() |
|
195 | |||
196 | /** |
||
197 | * |
||
198 | * @return array null |
||
199 | */ |
||
200 | 4 | private function getPackages() |
|
215 | |||
216 | /** |
||
217 | * What kind of capabilities this provider can detect |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | 1 | public function getDetectionCapabilities() |
|
225 | |||
226 | /** |
||
227 | * |
||
228 | * @param mixed $value |
||
229 | * @param string $group |
||
230 | * @param string $part |
||
231 | * @return boolean |
||
232 | */ |
||
233 | 2 | protected function isRealResult($value, $group = null, $part = null) |
|
256 | |||
257 | protected function getRealResult($value, $group = null, $part = null) |
||
265 | |||
266 | /** |
||
267 | * Parse the given user agent and return a result if possible |
||
268 | * |
||
269 | * @param string $userAgent |
||
270 | * @param array $headers |
||
271 | * |
||
272 | * @throws Exception\NoResultFoundException |
||
273 | * |
||
274 | * @return Model\UserAgent |
||
275 | */ |
||
276 | abstract public function parse($userAgent, array $headers = []); |
||
277 | } |
||
278 |