diff --git a/src/command/CommandReader.php b/src/command/CommandReader.php index 3eb43b75a3..ba4250c1cb 100644 --- a/src/command/CommandReader.php +++ b/src/command/CommandReader.php @@ -69,7 +69,7 @@ class CommandReader extends Thread{ $opts = getopt("", ["disable-readline", "enable-readline"]); - if(extension_loaded("readline") and (Utils::getOS() === "win" ? isset($opts["enable-readline"]) : !isset($opts["disable-readline"])) and !$this->isPipe(STDIN)){ + if(extension_loaded("readline") and (Utils::getOS() === Utils::OS_WINDOWS ? isset($opts["enable-readline"]) : !isset($opts["disable-readline"])) and !$this->isPipe(STDIN)){ $this->type = self::TYPE_READLINE; } } diff --git a/src/network/upnp/UPnP.php b/src/network/upnp/UPnP.php index 6862df185a..96bbb1eb4a 100644 --- a/src/network/upnp/UPnP.php +++ b/src/network/upnp/UPnP.php @@ -48,7 +48,7 @@ class UPnP implements NetworkInterface{ if(!Internet::$online){ throw new \RuntimeException("Server is offline"); } - if(Utils::getOS() !== "win"){ + if(Utils::getOS() !== Utils::OS_WINDOWS){ throw new \RuntimeException("UPnP is only supported on Windows"); } if(!class_exists("COM")){ diff --git a/src/utils/Process.php b/src/utils/Process.php index 77e2c320ef..37f751d1c6 100644 --- a/src/utils/Process.php +++ b/src/utils/Process.php @@ -54,7 +54,7 @@ final class Process{ $reserved = memory_get_usage(); $VmSize = null; $VmRSS = null; - if(Utils::getOS() === "linux" or Utils::getOS() === "android"){ + if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){ $status = @file_get_contents("/proc/self/status"); if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible"); @@ -92,7 +92,7 @@ final class Process{ $stack = 0; $heap = 0; - if(Utils::getOS() === "linux" or Utils::getOS() === "android"){ + if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){ $mappings = @file("/proc/self/maps"); if($mappings === false) throw new AssumptionFailedError("/proc/self/maps should always be accessible"); foreach($mappings as $line){ @@ -110,7 +110,7 @@ final class Process{ } public static function getThreadCount() : int{ - if(Utils::getOS() === "linux" or Utils::getOS() === "android"){ + if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){ $status = @file_get_contents("/proc/self/status"); if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible"); if(preg_match("/Threads:[ \t]+([0-9]+)/", $status, $matches) > 0){ @@ -132,11 +132,11 @@ final class Process{ $logger->syncFlushBuffer(); } switch(Utils::getOS()){ - case "win": + case Utils::OS_WINDOWS: exec("taskkill.exe /F /PID $pid > NUL"); break; - case "mac": - case "linux": + case Utils::OS_MACOS: + case Utils::OS_LINUX: default: if(function_exists("posix_kill")){ posix_kill($pid, 9); //SIGKILL diff --git a/src/utils/Terminal.php b/src/utils/Terminal.php index 61df61dc7f..d85b1154f7 100644 --- a/src/utils/Terminal.php +++ b/src/utils/Terminal.php @@ -177,14 +177,14 @@ abstract class Terminal{ } switch(Utils::getOS()){ - case "linux": - case "mac": - case "bsd": + case Utils::OS_LINUX: + case Utils::OS_MACOS: + case Utils::OS_BSD: self::getEscapeCodes(); return; - case "win": - case "android": + case Utils::OS_WINDOWS: + case Utils::OS_ANDROID: self::getFallbackEscapeCodes(); return; } diff --git a/src/utils/Timezone.php b/src/utils/Timezone.php index 8cd7bf6353..059e85598b 100644 --- a/src/utils/Timezone.php +++ b/src/utils/Timezone.php @@ -103,7 +103,7 @@ abstract class Timezone{ */ public static function detectSystemTimezone(){ switch(Utils::getOS()){ - case 'win': + case Utils::OS_WINDOWS: $regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/'; /* @@ -138,7 +138,7 @@ abstract class Timezone{ } return self::parseOffset($offset); - case 'linux': + case Utils::OS_LINUX: // Ubuntu / Debian. $data = @file_get_contents('/etc/timezone'); if($data !== false){ @@ -160,7 +160,7 @@ abstract class Timezone{ } return self::parseOffset($offset); - case 'mac': + case Utils::OS_MACOS: $filename = @readlink('/etc/localtime'); if($filename !== false and strpos($filename, '/usr/share/zoneinfo/') === 0){ $timezone = substr($filename, 20); diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 7069f85ccb..16f9f16d2a 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -84,6 +84,14 @@ use const STR_PAD_RIGHT; * Big collection of functions */ class Utils{ + public const OS_WINDOWS = "win"; + public const OS_IOS = "ios"; + public const OS_MACOS = "mac"; + public const OS_ANDROID = "android"; + public const OS_LINUX = "linux"; + public const OS_BSD = "bsd"; + public const OS_UNKNOWN = "other"; + /** @var string|null */ private static $os; /** @var UUID|null */ @@ -180,7 +188,7 @@ class Utils{ $machine .= sys_get_temp_dir(); $machine .= $extra; $os = Utils::getOS(); - if($os === "win"){ + if($os === Utils::OS_WINDOWS){ @exec("ipconfig /ALL", $mac); $mac = implode("\n", $mac); if(preg_match_all("#Physical Address[. ]{1,}: ([0-9A-F\\-]{17})#", $mac, $matches) > 0){ @@ -191,7 +199,7 @@ class Utils{ } $machine .= implode(" ", $matches[1]); //Mac Addresses } - }elseif($os === "linux"){ + }elseif($os === Utils::OS_LINUX){ if(file_exists("/etc/machine-id")){ $machine .= file_get_contents("/etc/machine-id"); }else{ @@ -206,9 +214,9 @@ class Utils{ $machine .= implode(" ", $matches[1]); //Mac Addresses } } - }elseif($os === "android"){ + }elseif($os === Utils::OS_ANDROID){ $machine .= @file_get_contents("/system/build.prop"); - }elseif($os === "mac"){ + }elseif($os === Utils::OS_MACOS){ $machine .= `system_profiler SPHardwareDataType | grep UUID`; } $data = $machine . PHP_MAXPATHLEN; @@ -243,22 +251,22 @@ class Utils{ $uname = php_uname("s"); if(stripos($uname, "Darwin") !== false){ if(strpos(php_uname("m"), "iP") === 0){ - self::$os = "ios"; + self::$os = self::OS_IOS; }else{ - self::$os = "mac"; + self::$os = self::OS_MACOS; } }elseif(stripos($uname, "Win") !== false or $uname === "Msys"){ - self::$os = "win"; + self::$os = self::OS_WINDOWS; }elseif(stripos($uname, "Linux") !== false){ if(@file_exists("/system/build.prop")){ - self::$os = "android"; + self::$os = self::OS_ANDROID; }else{ - self::$os = "linux"; + self::$os = self::OS_LINUX; } }elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){ - self::$os = "bsd"; + self::$os = self::OS_BSD; }else{ - self::$os = "other"; + self::$os = self::OS_UNKNOWN; } } @@ -275,8 +283,8 @@ class Utils{ } switch(Utils::getOS()){ - case "linux": - case "android": + case Utils::OS_LINUX: + case Utils::OS_ANDROID: if(($cpuinfo = @file('/proc/cpuinfo')) !== false){ foreach($cpuinfo as $l){ if(preg_match('/^processor[ \t]*:[ \t]*[0-9]+$/m', $l) > 0){ @@ -289,11 +297,11 @@ class Utils{ } } break; - case "bsd": - case "mac": + case Utils::OS_BSD: + case Utils::OS_MACOS: $processors = (int) `sysctl -n hw.ncpu`; break; - case "win": + case Utils::OS_WINDOWS: $processors = (int) getenv("NUMBER_OF_PROCESSORS"); break; }