mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
feat : admin log
This commit is contained in:
34
app/Trait/ClientOsTrait.php
Normal file
34
app/Trait/ClientOsTrait.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Trait;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
trait ClientOsTrait
|
||||
{
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly 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',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user