-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBiomeJsBinary.php
More file actions
58 lines (49 loc) · 1.96 KB
/
Copy pathBiomeJsBinary.php
File metadata and controls
58 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Kocal\BiomeJsBundle;
/**
* @internal
*/
final class BiomeJsBinary
{
public static function getBinaryName(): string
{
$os = strtolower(\PHP_OS);
$machine = strtolower(php_uname('m'));
return match (true) {
str_contains($os, 'darwin') => match ($machine) {
'arm64' => 'biome-darwin-arm64',
'x86_64' => 'biome-darwin-x64',
default => throw new \Exception(sprintf('No matching machine found for Darwin platform (Machine: %s).', $machine)),
},
str_contains($os, 'linux') => match ($machine) {
'arm64', 'aarch64' => self::isMusl() ? 'biome-linux-arm64-musl' : 'biome-linux-arm64',
'x86_64' => self::isMusl() ? 'biome-linux-x64-musl' : 'biome-linux-x64',
default => throw new \Exception(sprintf('No matching machine found for Linux platform (Machine: %s).', $machine)),
},
str_contains($os, 'win') => match ($machine) {
'arm64' => 'biome-win32-arm64.exe',
'x86_64', 'amd64' => 'biome-win32-x64.exe',
default => throw new \Exception(sprintf('No matching machine found for Windows platform (Machine: %s).', $machine)),
},
default => throw new \Exception(sprintf('Unknown platform or architecture (OS: %s, Machine: %s).', $os, $machine)),
};
}
/**
* Whether the current PHP environment is using musl libc.
* This is used to determine the correct Biome.js binary to download.
*/
private static function isMusl(): bool
{
static $isMusl = null;
if (is_bool($isMusl)) {
return $isMusl;
}
if (!\function_exists('phpinfo')) {
return $isMusl = false;
}
ob_start();
phpinfo(\INFO_GENERAL);
return $isMusl = 1 === preg_match('/--build=.*?-linux-musl/', ob_get_clean() ?: '');
}
}