<?php
 namespace TechSoft\Laravel\Agent; use Illuminate\Support\Facades\Request; class UserAgentUtil { const SOURCE_OTHER = 0; const SOURCE_APP = 1; const INFO_TYPE = 'type'; const INFO_VERSION = 'version'; const INFO_CHANNEL = 'channel'; const INFO_PLATFORM = 'platform'; const INFO_PLATFORM_VERSION = 'platformVersion'; const INFO_MODEL = 'model'; private static $_info = [ 'type' => null, 'version' => null, 'channel' => null, 'platform' => null, 'platformVersion' => null, 'model' => null, ]; public static function info($name = null) { if (null === $name) { return self::$_info; } return self::$_info[$name]; } public static function source($type = null, $channel = null) { $agentClient = Request::header('Soft-Client'); if (empty($agentClient)) { $agentClient = Request::header('User-Agent'); } if (null === $type) { $type = '[a-z]+'; } if (null === $channel) { $channel = '[a-z]+'; } if (preg_match('/^com\\.soft\\.(' . $type . ')\\/(\\d+\\.\\d+\\.\\d+) (' . $channel . ') \\((ios|android) (.*?); (.*?)\\)/', $agentClient, $mat)) { self::$_info['type'] = $mat[1]; self::$_info['version'] = $mat[2]; self::$_info['channel'] = $mat[3]; self::$_info['platform'] = $mat[4]; self::$_info['platformVersion'] = $mat[5]; self::$_info['model'] = $mat[6]; switch (self::$_info['platform']) { case 'ios': self::$_info['platform'] = Platform::IOS; break; case 'android': self::$_info['platform'] = Platform::ANDROID; break; default: return self::SOURCE_OTHER; } return self::SOURCE_APP; } return self::SOURCE_OTHER; } public static function clientId() { return trim(\TechOnline\Laravel\Http\Request::headerGet('api-device-id')); } }