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 | |||
92 | /** |
||
93 | * Return the name of the provider |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 1 | public function getName() |
|
101 | |||
102 | /** |
||
103 | * Get the homepage |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | 1 | public function getHomepage() |
|
111 | |||
112 | /** |
||
113 | * Get the package name |
||
114 | * |
||
115 | * @return string null |
||
116 | */ |
||
117 | 5 | public function getPackageName() |
|
121 | |||
122 | /** |
||
123 | * Return the version of the provider |
||
124 | * |
||
125 | * @return string null |
||
126 | */ |
||
127 | 2 | public function getVersion() |
|
153 | |||
154 | /** |
||
155 | * Get the last change date of the provider |
||
156 | * |
||
157 | * @return DateTime null |
||
158 | */ |
||
159 | 2 | public function getUpdateDate() |
|
187 | |||
188 | /** |
||
189 | * |
||
190 | * @return array null |
||
191 | */ |
||
192 | 4 | private function getPackages() |
|
207 | |||
208 | /** |
||
209 | * What kind of capabilities this provider can detect |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 1 | public function getDetectionCapabilities() |
|
217 | |||
218 | /** |
||
219 | * |
||
220 | * @param mixed $value |
||
221 | * @param array $additionalDefaultValues |
||
222 | * @return boolean |
||
223 | */ |
||
224 | 2 | protected function isRealResult($value, array $additionalDefaultValues = []) |
|
240 | |||
241 | /** |
||
242 | * Parse the given user agent and return a result if possible |
||
243 | * |
||
244 | * @param string $userAgent |
||
245 | * @param array $headers |
||
246 | * |
||
247 | * @throws Exception\NoResultFoundException |
||
248 | * |
||
249 | * @return Model\UserAgent |
||
250 | */ |
||
251 | abstract public function parse($userAgent, array $headers = []); |
||
252 | } |
||
253 |