1 | <?php |
||
9 | abstract class AbstractProvider |
||
10 | { |
||
11 | /** |
||
12 | * Name of the provider |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name; |
||
17 | |||
18 | /** |
||
19 | * Homepage of the provider |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $homepage; |
||
24 | |||
25 | /** |
||
26 | * Composer package name |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $packageName; |
||
31 | |||
32 | /** |
||
33 | * Version string for caching |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $version; |
||
38 | |||
39 | /** |
||
40 | * Last update date |
||
41 | * |
||
42 | * @var DateTime |
||
43 | */ |
||
44 | private $updateDate; |
||
45 | |||
46 | /** |
||
47 | * Per default the provider cannot detect anything |
||
48 | * Activate them in $detectionCapabilities |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $allDetectionCapabilities = [ |
||
53 | 'browser' => [ |
||
54 | 'name' => false, |
||
55 | 'version' => false, |
||
56 | ], |
||
57 | |||
58 | 'renderingEngine' => [ |
||
59 | 'name' => false, |
||
60 | 'version' => false, |
||
61 | ], |
||
62 | |||
63 | 'operatingSystem' => [ |
||
64 | 'name' => false, |
||
65 | 'version' => false, |
||
66 | ], |
||
67 | |||
68 | 'device' => [ |
||
69 | 'model' => false, |
||
70 | 'brand' => false, |
||
71 | 'type' => false, |
||
72 | 'isMobile' => false, |
||
73 | 'isTouch' => false, |
||
74 | ], |
||
75 | |||
76 | 'bot' => [ |
||
77 | 'isBot' => false, |
||
78 | 'name' => false, |
||
79 | 'type' => false, |
||
80 | ], |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * Set this in each Provider implementation |
||
85 | * |
||
86 | * @var array |
||
87 | */ |
||
88 | protected $detectionCapabilities = []; |
||
89 | |||
90 | protected $defaultValues = [ |
||
91 | 'general' => [], |
||
92 | ]; |
||
93 | |||
94 | /** |
||
95 | * Return the name of the provider |
||
96 | * |
||
97 | 1 | * @return string |
|
98 | */ |
||
99 | 1 | public function getName() |
|
100 | { |
||
101 | return $this->name; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get the homepage |
||
106 | * |
||
107 | 1 | * @return string |
|
108 | */ |
||
109 | 1 | public function getHomepage() |
|
113 | |||
114 | /** |
||
115 | * Get the package name |
||
116 | * |
||
117 | 5 | * @return string null |
|
118 | */ |
||
119 | 5 | public function getPackageName() |
|
123 | |||
124 | /** |
||
125 | * Return the version of the provider |
||
126 | * |
||
127 | 2 | * @return string null |
|
128 | */ |
||
129 | 2 | public function getVersion() |
|
155 | |||
156 | /** |
||
157 | * Get the last change date of the provider |
||
158 | * |
||
159 | 2 | * @return DateTime null |
|
160 | */ |
||
161 | 2 | public function getUpdateDate() |
|
189 | |||
190 | /** |
||
191 | * |
||
192 | 4 | * @return array null |
|
193 | */ |
||
194 | 4 | private function getPackages() |
|
209 | |||
210 | /** |
||
211 | * What kind of capabilities this provider can detect |
||
212 | * |
||
213 | 1 | * @return array |
|
214 | */ |
||
215 | 1 | public function getDetectionCapabilities() |
|
219 | |||
220 | /** |
||
221 | * |
||
222 | * @param mixed $value |
||
223 | * @param string $group |
||
224 | 2 | * @param string $part |
|
225 | * @return boolean |
||
226 | 2 | */ |
|
227 | 1 | protected function isRealResult($value, $group = null, $part = null) |
|
250 | |||
251 | /** |
||
252 | * Parse the given user agent and return a result if possible |
||
253 | * |
||
254 | * @param string $userAgent |
||
255 | * @param array $headers |
||
256 | * |
||
257 | * @throws Exception\NoResultFoundException |
||
258 | * |
||
259 | * @return Model\UserAgent |
||
260 | */ |
||
261 | abstract public function parse($userAgent, array $headers = []); |
||
262 | } |
||
263 |