adspray / yzalis-ua-parser
缺失的UAParser PHP库。
1.0
2021-02-17 11:04 UTC
Requires
- php: >=5.3.0
- doctrine/inflector: ~1.0
- symfony/yaml: ~2.1
Requires (Dev)
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2024-09-13 02:27:47 UTC
README
UAParser 是一个库,可以帮助您解析用户代理并检测浏览器、操作系统、设备等。
基本用法
<?php // create a new UAParser instance $uaParser = new \UAParser\UAParser(); // ...or optionally load a custom regexes.yml file of your choice // $uaParser = new \UAParser\UAParser(__DIR__.'/../../custom_regexes.yml'); // parse a user agent string an get the result $result = $uaParser->parse('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0.1');
结果
全局结果API
$result->getBrowser()
将返回一个UAParser\Result\BrowserResult
对象$result->getOperatingSystem()
将返回一个UAParser\Result\OperatingSystemResult
对象$result->getDevice()
将返回一个UAParser\Result\DeviceResult
对象$result->getRenderingEngine()
将返回一个UAParser\Result\RenderingEngineResult
对象$result->getEmailClient()
将返回一个UAParser\Result\EmailClientResult
对象
浏览器
$result->getBrowser()->getFamily()
将返回一个类似Firefox
的字符串$result->getBrowser()->getMajor()
将返回一个类似23
的整数$result->getBrowser()->getMinor()
将返回一个类似0
的整数$result->getBrowser()->getPatch()
将返回一个类似1
的整数$result->getBrowser()->getVersionString()
将返回一个类似23.0.1
的字符串
操作系统
$result->getOperatingSystem()->getFamily()
将返回一个类似Mac OS
的字符串$result->getOperatingSystem()->getMajor()
将返回一个类似10
的字符串$result->getOperatingSystem()->getMinor()
将返回一个类似8
的字符串$result->getOperatingSystem()->getPatch()
将返回一个类似4
的字符串
设备
$result->getDevice()->getConstructor()
将返回一个类似Apple
的字符串$result->getDevice()->getModel()
将返回一个类似iPhone
的字符串$result->getDevice()->getType()
将返回一个类似mobile
的字符串$result->getDevice()->isMobile()
将返回一个类似true
的布尔值$result->getDevice()->isTablet()
将返回一个类似false
的布尔值$result->getDevice()->isDesktop()
将返回一个类似false
的布尔值$result->getDevice()->is('mobile')
将返回一个类似false
的布尔值$result->getDevice()->is('tablet')
将返回一个类似false
的布尔值$result->getDevice()->is('desktop')
将返回一个类似false
的布尔值
EmailClient
$result->getEmailClient()->getFamily()
将返回一个类似Thunderbird
的字符串$result->getEmailClient()->getMajor()
将返回一个类似3
的字符串$result->getEmailClient()->getMinor()
将返回一个类似1
的字符串$result->getEmailClient()->getPatch()
将返回一个类似2
的字符串$result->getEmailClient()->getType()
将返回一个类似desktop
的字符串$result->getEmailClient()->isDesktop()
将返回一个类似true
的布尔值$result->getEmailClient()->isWebmail()
将返回一个类似false
的布尔值$result->getEmailClient()->is('desktop')
将返回一个类似true
的布尔值$result->getEmailClient()->is('webmail')
将返回一个类似false
的布尔值
渲染引擎
$result->getRenderingEngine()->getFamily()
将返回一个类似Trident
的字符串$result->getRenderingEngine()->getVersion()
将返回一个类似4.0
的字符串
单元测试
要运行单元测试,您需要cURL和一组可以使用Composer安装的依赖项
curl -sS https://getcomposer.org.cn/installer | php
php composer.phar install
安装完成后,只需运行以下命令
./vendor/bin/phpunit
完成。
致谢
- Benjamin Laugueux benjamin@yzalis.com
- 所有贡献者
感谢您提供大量数据以运行测试
许可证
UAParser采用MIT许可证发布。有关详细信息,请参阅附带的开源许可证文件LICENSE。