1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
namespace hexydec\agentzero; |
4
|
|
|
|
5
|
|
|
class frameworks { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Generates a configuration array for matching app frameworks |
9
|
|
|
* |
10
|
|
|
* @return array<string,props> An array with keys representing the string to match, and values a props object defining how to generate the match and which properties to set |
11
|
|
|
*/ |
12
|
6 |
|
public static function get() : array { |
13
|
1 |
|
return [ |
14
|
1 |
|
'Electron/' => new props('start', fn (string $value) : array => [ |
15
|
5 |
|
'framework' => 'Electron', |
16
|
5 |
|
'frameworkversion' => \explode('/', $value, 3)[1] |
17
|
5 |
|
]), |
18
|
1 |
|
'MAUI' => new props('start', [ |
19
|
1 |
|
'framework' => 'MAUI' |
20
|
1 |
|
]), |
21
|
1 |
|
'Cordova' => new props('start', fn (string $value) : array => [ |
22
|
2 |
|
'framework' => 'Cordova', |
23
|
2 |
|
'frameworkversion' => \explode('/', $value, 3)[1] |
24
|
2 |
|
]), |
25
|
1 |
|
'Alamofire/' => new props('start', fn (string $value) : array => [ |
26
|
1 |
|
'framework' => 'Alamofire', |
27
|
1 |
|
'frameworkversion' => \explode('/', $value, 3)[1] |
28
|
1 |
|
]), |
29
|
1 |
|
'.NET CLR ' => new props('start', function (string $value, int $i, array $tokens) : array { |
30
|
|
|
|
31
|
|
|
// find latest version as often specifdies many versions |
32
|
6 |
|
$levels = []; |
33
|
6 |
|
for ($n = $i; $n < \count($tokens); $n++) { // may happen multiple times if there are multiple captures, but only look forward as only the first will be written |
|
|
|
|
34
|
6 |
|
if (\mb_stripos($tokens[$n], '.NET CLR ') === 0) { |
35
|
6 |
|
$ver = \array_map('\\intval', \explode('.', \mb_substr($tokens[$n], 9))); |
36
|
6 |
|
foreach ($ver AS $key => $item) { |
37
|
6 |
|
if ($item > ($levels[$key] ?? 0)) { |
38
|
6 |
|
$levels = $ver; |
39
|
6 |
|
} elseif ($item < ($levels[$key] ?? 0)) { |
40
|
4 |
|
break; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
6 |
|
return [ |
46
|
6 |
|
'framework' => '.NET Common Language Runtime', |
47
|
6 |
|
'frameworkversion' => \implode('.', $levels) |
48
|
6 |
|
]; |
49
|
1 |
|
}), |
50
|
1 |
|
'libwww-perl/' => new props('start', fn (string $value) : array => [ |
51
|
2 |
|
'type' => 'robot', |
52
|
2 |
|
'category' => 'scraper', |
53
|
2 |
|
'app' => 'LibWWW Perl', |
54
|
2 |
|
'appname' => 'libwww-perl', |
55
|
2 |
|
'appversion' => \explode('/', $value, 3)[1], |
56
|
2 |
|
'framework' => 'LibWWW Perl', |
57
|
2 |
|
'frameworkversion' => \explode('/', $value, 3)[1] |
58
|
2 |
|
]) |
59
|
1 |
|
]; |
60
|
|
|
} |
61
|
|
|
} |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: