mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 22:47:50 +08:00
34 lines
803 B
PHP
34 lines
803 B
PHP
<?php
|
|
|
|
namespace App\Common\Trait;
|
|
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\HttpServer\Contract\RequestInterface;
|
|
|
|
trait ClientOsTrait
|
|
{
|
|
/**
|
|
* @var RequestInterface
|
|
*/
|
|
#[Inject]
|
|
protected RequestInterface $request;
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getClientOs(): string
|
|
{
|
|
$userAgent = $this->request->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',
|
|
};
|
|
}
|
|
} |