[Galactica] Improve Windows compatibility

This commit is contained in:
Andrés Montañez 2022-04-10 18:53:26 -03:00
parent fc8da5b229
commit a370c1c0c9
No known key found for this signature in database
GPG key ID: 97E9F675F4C03DE2
2 changed files with 15 additions and 5 deletions

View file

@ -75,6 +75,11 @@ class Runtime
return stripos(PHP_OS, 'WIN') === 0;
}
public function hasPosix(): bool
{
return function_exists('posix_getpwuid');
}
/**
* Generate the Release ID
*/
@ -471,13 +476,13 @@ class Runtime
*/
public function getCurrentUser(): string
{
// Windows fallback
if (!function_exists('posix_getpwuid')) {
return getenv('USERNAME') ?: '';
if ($this->hasPosix()) {
$userData = posix_getpwuid(posix_geteuid());
return $userData['name'];
}
$userData = posix_getpwuid(posix_geteuid());
return $userData['name'];
// Windows fallback
return strval(getenv('USERNAME'));
}
/**

View file

@ -16,4 +16,9 @@ class RuntimeWindowsMockup extends RuntimeMockup
{
return true;
}
public function hasPosix(): bool
{
return false;
}
}