|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
namespace hexydec\agentzero; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @phpstan-import-type MatchConfig from config |
|
7
|
|
|
*/ |
|
8
|
|
|
class platforms { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Generates a configuration array for matching platforms |
|
12
|
|
|
* |
|
13
|
|
|
* @return MatchConfig An array with keys representing the string to match, and a value of an array containing parsing and output settings |
|
|
|
|
|
|
14
|
|
|
*/ |
|
15
|
40 |
|
public static function get() : array { |
|
16
|
1 |
|
$fn = [ |
|
17
|
1 |
|
'platformspace' => function (string $value) : array { |
|
18
|
|
|
$parts = \explode(' ', $value, 2); |
|
19
|
|
|
return [ |
|
20
|
|
|
'platform' => $parts[0], |
|
21
|
|
|
'platformversion' => $parts[1] ?? null |
|
22
|
|
|
]; |
|
23
|
1 |
|
}, |
|
24
|
1 |
|
'platformlinux' => function (string $value) : array { |
|
25
|
10 |
|
if (!\str_starts_with($value, 'Red Hat/') && ($platform = \mb_strstr($value, ' ', true)) !== false) { |
|
26
|
|
|
$value = $platform; |
|
27
|
|
|
} |
|
28
|
10 |
|
$parts = \explode('/', $value, 2); |
|
29
|
10 |
|
if (!isset($parts[1])) { |
|
30
|
8 |
|
$parts = \explode('-', $value, 2); |
|
31
|
|
|
} |
|
32
|
10 |
|
if (!isset($parts[1])) { |
|
33
|
6 |
|
$parts = \explode(' ', $value, 2); |
|
34
|
|
|
} |
|
35
|
10 |
|
return [ |
|
36
|
10 |
|
'type' => 'human', |
|
37
|
10 |
|
'category' => 'desktop', |
|
38
|
10 |
|
'kernel' => 'Linux', |
|
39
|
10 |
|
'platform' => $parts[0] === 'Web0S' ? 'WebOS' : $parts[0], |
|
40
|
10 |
|
'platformversion' => isset($parts[1]) && \strspn($parts[1], '0123456789.-_') > 0 ? $parts[1] : null |
|
41
|
10 |
|
]; |
|
42
|
1 |
|
}, |
|
43
|
1 |
|
'platformwindows' => function (string $value) : array { |
|
44
|
40 |
|
$mapping = [ |
|
45
|
40 |
|
'5.0' => '2000', |
|
46
|
40 |
|
'5.1' => 'XP', |
|
47
|
40 |
|
'5.2' => 'XP', |
|
48
|
40 |
|
'6.0' => 'Vista', |
|
49
|
40 |
|
'6.1' => '7', |
|
50
|
40 |
|
'6.2' => '8', |
|
51
|
40 |
|
'6.3' => '8.1', |
|
52
|
40 |
|
'10.0' => '10' |
|
53
|
40 |
|
]; |
|
54
|
40 |
|
$version = null; |
|
55
|
40 |
|
foreach (['Windows NT ', 'Windows '] AS $item) { |
|
56
|
40 |
|
if (($pos = \mb_stripos($value, $item)) !== false) { |
|
57
|
40 |
|
$version = \explode(' ', \mb_substr($value, $pos + \mb_strlen($item)))[0]; |
|
58
|
40 |
|
break; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
40 |
|
return [ |
|
62
|
40 |
|
'type' => 'human', |
|
63
|
40 |
|
'category' => 'desktop', |
|
64
|
40 |
|
'kernel' => 'Windows NT', |
|
65
|
40 |
|
'platform' => 'Windows', |
|
66
|
40 |
|
'platformversion' => $mapping[$version] ?? $version |
|
67
|
40 |
|
]; |
|
68
|
1 |
|
} |
|
69
|
1 |
|
]; |
|
70
|
|
|
|
|
71
|
1 |
|
return [ |
|
72
|
|
|
|
|
73
|
|
|
// platforms |
|
74
|
1 |
|
'Windows NT ' => [ |
|
75
|
1 |
|
'match' => 'any', |
|
76
|
1 |
|
'categories' => $fn['platformwindows'] |
|
77
|
1 |
|
], |
|
78
|
1 |
|
'Windows Phone' => [ |
|
79
|
1 |
|
'match' => 'start', |
|
80
|
1 |
|
'categories' => function (string $value) : array { |
|
81
|
3 |
|
$version = \mb_substr($value, 14); |
|
82
|
3 |
|
return [ |
|
83
|
3 |
|
'type' => 'human', |
|
84
|
3 |
|
'category' => 'mobile', |
|
85
|
3 |
|
'platform' => 'Windows Phone', |
|
86
|
3 |
|
'platformversion' => $version, |
|
87
|
3 |
|
'kernel' => \intval($version) >= 8 ? 'Windows NT' : 'Windows CE' |
|
88
|
3 |
|
]; |
|
89
|
1 |
|
} |
|
90
|
1 |
|
], |
|
91
|
1 |
|
'Win98' => [ |
|
92
|
1 |
|
'match' => 'start', |
|
93
|
1 |
|
'categories' => [ |
|
94
|
1 |
|
'type' => 'human', |
|
95
|
1 |
|
'category' => 'desktop', |
|
96
|
1 |
|
'architecture' => 'x86', |
|
97
|
1 |
|
'bits' => 32, |
|
98
|
1 |
|
'kernel' => 'MS-DOS', |
|
99
|
1 |
|
'platform' => 'Windows', |
|
100
|
1 |
|
'platformversion' => '98' |
|
101
|
1 |
|
] |
|
102
|
1 |
|
], |
|
103
|
1 |
|
'WinNT' => [ |
|
104
|
1 |
|
'match' => 'start', |
|
105
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
106
|
1 |
|
'type' => 'human', |
|
107
|
1 |
|
'category' => 'desktop', |
|
108
|
1 |
|
'architecture' => 'x86', |
|
109
|
1 |
|
'bits' => 32, |
|
110
|
1 |
|
'kernel' => 'Windows NT', |
|
111
|
1 |
|
'platform' => 'Windows', |
|
112
|
1 |
|
'platformversion' => \mb_substr($value, 5) |
|
113
|
1 |
|
] |
|
114
|
1 |
|
], |
|
115
|
1 |
|
'Windows' => [ |
|
116
|
1 |
|
'match' => 'any', |
|
117
|
1 |
|
'categories' => $fn['platformwindows'] |
|
118
|
1 |
|
], |
|
119
|
1 |
|
'Mac OS X' => [ |
|
120
|
1 |
|
'match' => 'any', |
|
121
|
1 |
|
'categories' => function (string $value) : array { |
|
122
|
23 |
|
$version = \str_replace('_', '.', \mb_substr($value, \mb_stripos($value, 'Mac OS X') + 9)); |
|
123
|
23 |
|
$register = $version && \intval(\explode('.', $version)[1] ?? 0) >= 6 ? 64 : null; |
|
124
|
23 |
|
return [ |
|
125
|
23 |
|
'type' => 'human', |
|
126
|
23 |
|
'category' => 'desktop', |
|
127
|
23 |
|
'kernel' => 'Linux', |
|
128
|
23 |
|
'platform' => 'Mac OS X', |
|
129
|
23 |
|
'platformversion' => $version === '' ? null : $version, |
|
130
|
23 |
|
'bits' => $register |
|
131
|
23 |
|
]; |
|
132
|
1 |
|
} |
|
133
|
1 |
|
], |
|
134
|
1 |
|
'AppleTV' => [ |
|
135
|
1 |
|
'match' => 'exact', |
|
136
|
1 |
|
'categories' => [ |
|
137
|
1 |
|
'type' => 'human', |
|
138
|
1 |
|
'category' => 'tv', |
|
139
|
1 |
|
'device' => 'AppleTV', |
|
140
|
1 |
|
'platform' => 'tvOS', |
|
141
|
1 |
|
'bits' => 64 |
|
142
|
1 |
|
] |
|
143
|
1 |
|
], |
|
144
|
1 |
|
'iOS/' => [ |
|
145
|
1 |
|
'match' => 'start', |
|
146
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
147
|
1 |
|
'type' => 'human', |
|
148
|
1 |
|
'category' => 'mobile', |
|
149
|
1 |
|
'platform' => 'iOS', |
|
150
|
1 |
|
'platformversion' => \mb_substr($value, 4) |
|
151
|
1 |
|
] |
|
152
|
1 |
|
], |
|
153
|
1 |
|
'CrOS' => [ |
|
154
|
1 |
|
'match' => 'start', |
|
155
|
1 |
|
'categories' => function (string $value) : array { |
|
156
|
4 |
|
$parts = \explode(' ', $value); |
|
157
|
4 |
|
return [ |
|
158
|
4 |
|
'type' => 'human', |
|
159
|
4 |
|
'category' => 'desktop', |
|
160
|
4 |
|
'platform' => 'Chrome OS', |
|
161
|
4 |
|
'platformversion' => $parts[2] ?? null |
|
162
|
4 |
|
]; |
|
163
|
1 |
|
} |
|
164
|
1 |
|
], |
|
165
|
1 |
|
'Kindle/' => [ |
|
166
|
1 |
|
'match' => 'start', |
|
167
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
168
|
1 |
|
'type' => 'human', |
|
169
|
1 |
|
'category' => 'ebook', |
|
170
|
1 |
|
'platform' => 'Kindle', |
|
171
|
1 |
|
'platformversion' => \mb_substr($value, 7) |
|
172
|
1 |
|
] |
|
173
|
1 |
|
], |
|
174
|
1 |
|
'Tizen' => [ |
|
175
|
1 |
|
'match' => 'start', |
|
176
|
1 |
|
'categories' => function (string $value) : array { |
|
177
|
1 |
|
$parts = \explode(' ', $value, 2); |
|
178
|
1 |
|
return [ |
|
179
|
1 |
|
'type' => 'human', |
|
180
|
1 |
|
'category' => 'desktop', |
|
181
|
1 |
|
'kernel' => 'Linux', |
|
182
|
1 |
|
'platform' => $parts[0], |
|
183
|
1 |
|
'platformversion' => $parts[1] ?? null |
|
184
|
1 |
|
]; |
|
185
|
1 |
|
} |
|
186
|
1 |
|
], |
|
187
|
1 |
|
'Ubuntu' => [ |
|
188
|
1 |
|
'match' => 'start', |
|
189
|
1 |
|
'categories' => $fn['platformlinux'] |
|
190
|
1 |
|
], |
|
191
|
1 |
|
'Kubuntu' => [ |
|
192
|
1 |
|
'match' => 'start', |
|
193
|
1 |
|
'categories' => $fn['platformlinux'] |
|
194
|
1 |
|
], |
|
195
|
1 |
|
'Mint' => [ |
|
196
|
1 |
|
'match' => 'start', |
|
197
|
1 |
|
'categories' => $fn['platformlinux'] |
|
198
|
1 |
|
], |
|
199
|
1 |
|
'SUSE' => [ |
|
200
|
1 |
|
'match' => 'start', |
|
201
|
1 |
|
'categories' => $fn['platformlinux'] |
|
202
|
1 |
|
], |
|
203
|
1 |
|
'Red Hat/' => [ |
|
204
|
1 |
|
'match' => 'start', |
|
205
|
1 |
|
'categories' => $fn['platformlinux'] |
|
206
|
1 |
|
], |
|
207
|
1 |
|
'Debian' => [ |
|
208
|
1 |
|
'match' => 'start', |
|
209
|
1 |
|
'categories' => $fn['platformlinux'] |
|
210
|
1 |
|
], |
|
211
|
1 |
|
'Darwin' => [ |
|
212
|
1 |
|
'match' => 'start', |
|
213
|
1 |
|
'categories' => $fn['platformlinux'] |
|
214
|
1 |
|
], |
|
215
|
1 |
|
'Fedora' => [ |
|
216
|
1 |
|
'match' => 'start', |
|
217
|
1 |
|
'categories' => $fn['platformlinux'] |
|
218
|
1 |
|
], |
|
219
|
1 |
|
'CentOS' => [ |
|
220
|
1 |
|
'match' => 'start', |
|
221
|
1 |
|
'categories' => $fn['platformlinux'] |
|
222
|
1 |
|
], |
|
223
|
1 |
|
'Rocky' => [ |
|
224
|
1 |
|
'match' => 'start', |
|
225
|
1 |
|
'categories' => $fn['platformlinux'] |
|
226
|
1 |
|
], |
|
227
|
1 |
|
'ArchLinux' => [ |
|
228
|
1 |
|
'match' => 'exact', |
|
229
|
1 |
|
'categories' => fn () : array => [ |
|
230
|
|
|
'type' => 'human', |
|
231
|
|
|
'category' => 'desktop', |
|
232
|
|
|
'kernel' => 'Linux', |
|
233
|
|
|
'platform' => 'Arch', |
|
234
|
|
|
] |
|
235
|
1 |
|
], |
|
236
|
1 |
|
'Arch' => [ |
|
237
|
1 |
|
'match' => 'exact', |
|
238
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
239
|
|
|
'type' => 'human', |
|
240
|
|
|
'category' => 'desktop', |
|
241
|
|
|
'kernel' => 'Linux', |
|
242
|
|
|
'platform' => $value, |
|
243
|
|
|
] |
|
244
|
1 |
|
], |
|
245
|
1 |
|
'Web0S' => [ |
|
246
|
1 |
|
'match' => 'exact', |
|
247
|
1 |
|
'categories' => $fn['platformlinux'] |
|
248
|
1 |
|
], |
|
249
|
1 |
|
'webOSTV' => [ |
|
250
|
1 |
|
'match' => 'exact', |
|
251
|
1 |
|
'categories' => [ |
|
252
|
1 |
|
'type' => 'human', |
|
253
|
1 |
|
'category' => 'tv', |
|
254
|
1 |
|
'kernel' => 'Linux', |
|
255
|
1 |
|
'platform' => 'WebOS' |
|
256
|
1 |
|
] |
|
257
|
1 |
|
], |
|
258
|
1 |
|
'WEBOS' => [ |
|
259
|
1 |
|
'match' => 'start', |
|
260
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
261
|
1 |
|
'type' => 'human', |
|
262
|
1 |
|
'category' => 'tv', |
|
263
|
1 |
|
'kernel' => 'Linux', |
|
264
|
1 |
|
'platform' => 'WebOS', |
|
265
|
1 |
|
'platformversion' => \mb_substr($value, 5) |
|
266
|
1 |
|
] |
|
267
|
1 |
|
], |
|
268
|
1 |
|
'SunOS' => [ |
|
269
|
1 |
|
'match' => 'start', |
|
270
|
1 |
|
'categories' => [ |
|
271
|
1 |
|
'type' => 'human', |
|
272
|
1 |
|
'category' => 'desktop', |
|
273
|
1 |
|
'kernel' => 'unix', |
|
274
|
1 |
|
'platform' => 'Solaris', |
|
275
|
1 |
|
] |
|
276
|
1 |
|
], |
|
277
|
1 |
|
'AmigaOS' => [ |
|
278
|
1 |
|
'match' => 'any', |
|
279
|
1 |
|
'categories' => function (string $value) : array { |
|
280
|
3 |
|
if (($pos = \mb_stripos($value, 'AmigaOS')) !== false) { |
|
281
|
3 |
|
$value = \mb_substr($value, $pos); |
|
282
|
|
|
} |
|
283
|
3 |
|
$parts = \explode(' ', $value, 2); |
|
284
|
3 |
|
return [ |
|
285
|
3 |
|
'type' => 'human', |
|
286
|
3 |
|
'category' => 'desktop', |
|
287
|
3 |
|
'kernel' => 'Exec', |
|
288
|
3 |
|
'platform' => $parts[0], |
|
289
|
3 |
|
'platformversion' => isset($parts[1]) && \strspn($parts[1], '0123456789.-_') === \strlen($parts[1]) ? $parts[1] : null |
|
290
|
3 |
|
]; |
|
291
|
1 |
|
} |
|
292
|
1 |
|
], |
|
293
|
1 |
|
'Fuchsia' => [ |
|
294
|
1 |
|
'match' => 'exact', |
|
295
|
1 |
|
'categories' => function (string $value, int $i, array $tokens) : array { |
|
296
|
1 |
|
$os = \explode(' ', $tokens[++$i], 2); |
|
297
|
1 |
|
return [ |
|
298
|
1 |
|
'type' => 'human', |
|
299
|
1 |
|
'category' => 'mobile', |
|
300
|
1 |
|
'kernel' => 'Zircon', |
|
301
|
1 |
|
'platform' => $value, |
|
302
|
1 |
|
'platformversion' => isset($os[1]) && \strspn($os[1], '0123456789.-_', \strlen($os[0])) === \strlen($os[1]) ? $os[1] : null |
|
303
|
1 |
|
]; |
|
304
|
1 |
|
} |
|
305
|
1 |
|
], |
|
306
|
1 |
|
'Maemo' => [ |
|
307
|
1 |
|
'match' => 'exact', |
|
308
|
1 |
|
'categories' => function (string $value, int $i, array $tokens) : array { |
|
309
|
1 |
|
$os = \explode(' ', $tokens[++$i], 2); |
|
310
|
1 |
|
return [ |
|
311
|
1 |
|
'type' => 'human', |
|
312
|
1 |
|
'category' => 'mobile', |
|
313
|
1 |
|
'kernel' => 'Linux', |
|
314
|
1 |
|
'platform' => $value, |
|
315
|
1 |
|
'platformversion' => isset($os[1]) && \strspn($os[1], '0123456789.-_', \strlen($os[0])) === \strlen($os[1]) ? $os[1] : null |
|
316
|
1 |
|
]; |
|
317
|
1 |
|
} |
|
318
|
1 |
|
], |
|
319
|
1 |
|
'J2ME/MIDP' => [ |
|
320
|
1 |
|
'match' => 'exact', |
|
321
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
322
|
2 |
|
'type' => 'human', |
|
323
|
2 |
|
'category' => 'mobile', |
|
324
|
2 |
|
'kernel' => 'Java VM', |
|
325
|
2 |
|
'platform' => $value |
|
326
|
2 |
|
] |
|
327
|
1 |
|
], |
|
328
|
1 |
|
'Haiku' => [ |
|
329
|
1 |
|
'match' => 'any', |
|
330
|
1 |
|
'categories' => function (string $value) : array { |
|
331
|
3 |
|
$parts = \explode('/', $value, 2); |
|
332
|
3 |
|
return [ |
|
333
|
3 |
|
'type' => 'human', |
|
334
|
3 |
|
'category' => 'desktop', |
|
335
|
3 |
|
'kernel' => 'Haiku', |
|
336
|
3 |
|
'platform' => 'Haiku', |
|
337
|
3 |
|
'platformversion' => $parts[1] ?? null |
|
338
|
3 |
|
]; |
|
339
|
1 |
|
} |
|
340
|
1 |
|
], |
|
341
|
1 |
|
'BeOS' => [ |
|
342
|
1 |
|
'match' => 'start', |
|
343
|
1 |
|
'categories' => function (string $value) : array { |
|
344
|
1 |
|
$parts = \explode('/', $value, 2); |
|
345
|
1 |
|
return [ |
|
346
|
1 |
|
'type' => 'human', |
|
347
|
1 |
|
'category' => 'desktop', |
|
348
|
1 |
|
'kernel' => 'BeOS', |
|
349
|
1 |
|
'platform' => 'BeOS', |
|
350
|
1 |
|
'platformversion' => $parts[1] ?? null |
|
351
|
1 |
|
]; |
|
352
|
1 |
|
} |
|
353
|
1 |
|
], |
|
354
|
1 |
|
'Android' => [ |
|
355
|
1 |
|
'match' => 'start', |
|
356
|
1 |
|
'categories' => function (string $value, int $i, array $tokens) : array { |
|
357
|
30 |
|
$os = \explode(' ', $value, 3); |
|
358
|
30 |
|
$device = empty($tokens[++$i]) || \strlen($tokens[$i]) <= 2 ? [] : devices::getDevice($tokens[$i]); |
|
359
|
30 |
|
return \array_merge($device, [ |
|
360
|
30 |
|
'type' => 'human', |
|
361
|
30 |
|
'category' => 'tablet', |
|
362
|
30 |
|
'platform' => $os[0], |
|
363
|
30 |
|
'platformversion' => $os[1] ?? null |
|
364
|
30 |
|
]); |
|
365
|
1 |
|
} |
|
366
|
1 |
|
], |
|
367
|
1 |
|
'Linux' => [ |
|
368
|
1 |
|
'match' => 'any', |
|
369
|
1 |
|
'categories' => [ |
|
370
|
1 |
|
'kernel' => 'Linux', |
|
371
|
1 |
|
'platform' => 'Linux' |
|
372
|
1 |
|
] |
|
373
|
1 |
|
], |
|
374
|
1 |
|
'X11' => [ |
|
375
|
1 |
|
'match' => 'exact', |
|
376
|
1 |
|
'categories' => function (string $value, int $i, array $tokens) : array { |
|
377
|
28 |
|
$os = \explode(' ', $tokens[++$i] ?? '', 2); |
|
378
|
28 |
|
return [ |
|
379
|
28 |
|
'category' => 'desktop', |
|
380
|
28 |
|
'kernel' => 'Linux', |
|
381
|
28 |
|
'platform' => $os[0] ?: 'X11', |
|
382
|
28 |
|
'platformversion' => isset($os[1]) && \strspn($os[1], '0123456789.-_', \strlen($os[0])) === \strlen($os[1]) ? $os[1] : null |
|
383
|
28 |
|
]; |
|
384
|
1 |
|
} |
|
385
|
1 |
|
], |
|
386
|
1 |
|
'OS/2' => [ |
|
387
|
1 |
|
'match' => 'exact', |
|
388
|
1 |
|
'categories' => [ |
|
389
|
1 |
|
'category' => 'desktop', |
|
390
|
1 |
|
'platform' => 'OS/2' |
|
391
|
1 |
|
] |
|
392
|
1 |
|
], |
|
393
|
1 |
|
'Version/' => [ |
|
394
|
1 |
|
'match' => 'start', |
|
395
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
396
|
35 |
|
'platformversion' => \mb_substr($value, 8) |
|
397
|
35 |
|
] |
|
398
|
1 |
|
] |
|
399
|
1 |
|
]; |
|
400
|
|
|
} |
|
401
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths