|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
namespace hexydec\agentzero; |
|
4
|
|
|
|
|
5
|
|
|
class config { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Retrieves the configuration |
|
9
|
|
|
* |
|
10
|
|
|
* @return array{ignore: array<int,string>, single: array<int,string>, match: array<string,props>} An array of configuration values |
|
11
|
|
|
*/ |
|
12
|
100 |
|
public static function get(array $config = []) : ?array { |
|
13
|
100 |
|
static $default = []; |
|
14
|
100 |
|
if (empty($default)) { |
|
15
|
1 |
|
$default = [ |
|
16
|
1 |
|
'ignore' => ['mozilla/5.0', 'mozilla/5.0+', 'mozilla/4.0', 'applewebkit/537.36', 'khtml', 'like gecko', 'khtml', 'like gecko', 'safari/537.36', 'compatible', 'gecko/20100101', 'u', 'u', 'like', 'somewhat like gecko', 'wv', 'embeddedwb 14.52 from:'], // tokens that are meaningless and should be removed before processing |
|
17
|
1 |
|
'single' => ['Mobile', 'Moblie', 'VR', 'Large Screen', 'Smart TV', 'Tablet', 'SmartTV', 'TV', 'DTV', 'Ubuntu', 'Touch', 'Linux', 'Gentoo', 'Gecko', 'AppleWebKit/537.36'], // tokens that should be matched on their own |
|
18
|
1 |
|
'match' => \array_merge( |
|
19
|
1 |
|
special::get(), // to override others |
|
20
|
1 |
|
languages::get(), |
|
21
|
1 |
|
crawlers::get(), |
|
22
|
1 |
|
urls::get(), |
|
23
|
1 |
|
devices::get(), |
|
24
|
1 |
|
categories::get(), |
|
25
|
1 |
|
engines::get(), |
|
26
|
1 |
|
browsers::get(), |
|
27
|
1 |
|
platforms::get(), |
|
28
|
1 |
|
architectures::get(), |
|
29
|
1 |
|
other::get(), |
|
30
|
1 |
|
apps::get(), |
|
31
|
1 |
|
frameworks::get() |
|
32
|
1 |
|
), |
|
33
|
1 |
|
'versionssource' => 'https://raw.githubusercontent.com/hexydec/versions/refs/heads/main/dist/versions.json', // browser version data source |
|
34
|
1 |
|
'versionscache' => null, // location of the cache file, null to not fetch version data |
|
35
|
1 |
|
'versionscachelife' => 604800, // how long to cache for |
|
36
|
1 |
|
'currentdate' => null // the point in time to calculate the browser data from, may be in the past (DateTime object) |
|
37
|
1 |
|
]; |
|
38
|
|
|
} |
|
39
|
100 |
|
return \array_replace_recursive($default, $config); |
|
40
|
|
|
} |
|
41
|
|
|
} |