diff --git a/src/Support/Request.php b/src/Support/Request.php index de9a233..e183368 100644 --- a/src/Support/Request.php +++ b/src/Support/Request.php @@ -14,8 +14,9 @@ use Hyperf\HttpServer\Contract\RequestInterface; use Mine\Support\Request\ClientIpRequestTrait; +use Mine\Support\Request\ClientOsTrait; class Request extends \Hyperf\HttpServer\Request implements RequestInterface { - use ClientIpRequestTrait; + use ClientIpRequestTrait,ClientOsTrait; } diff --git a/src/Support/Request/ClientOsTrait.php b/src/Support/Request/ClientOsTrait.php new file mode 100644 index 0000000..e8b0e2f --- /dev/null +++ b/src/Support/Request/ClientOsTrait.php @@ -0,0 +1,37 @@ +header('user-agent'); + if (empty($userAgent)) { + return 'Unknown'; + } + return match (true) { + preg_match('/win/i', $userAgent) => 'Windows', + preg_match('/mac/i', $userAgent) => 'MAC', + preg_match('/linux/i', $userAgent) => 'Linux', + preg_match('/unix/i', $userAgent) => 'Unix', + preg_match('/bsd/i', $userAgent) => 'BSD', + default => 'Other', + }; + } +}