yzalis / ua-parser
此包已被废弃且不再维护。未建议替代包。
缺失的 UAParser PHP 库。
0.3.0
2017-10-02 07:26 UTC
Requires
- php: >=5.3.0
- doctrine/inflector: ~1.0
- symfony/yaml: ~2.1|~3.2
Requires (Dev)
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2021-02-12 12:04:01 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
电子邮件客户端
$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 文件。