-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(src): add ClientOsTrait for operating system detection
- Add ClientOsTrait to detect client operating system from user agent - Implement os() method to return OS name or 'Unknown' if not detectable - Update multiple files with changes related to this new feature
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\Support\Request; | ||
|
||
use Mine\Support\Request; | ||
|
||
/** | ||
* @mixin Request | ||
*/ | ||
trait ClientOsTrait | ||
{ | ||
public function os(): string | ||
{ | ||
$userAgent = $this->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', | ||
}; | ||
} | ||
} |