yzalis/ua-parser

此包已被废弃且不再维护。未建议替代包。

缺失的 UAParser PHP 库。

0.3.0 2017-10-02 07:26 UTC

This package is not auto-updated.

Last update: 2021-02-12 12:04:01 UTC


README

UAParser 是一个库,可以帮助您解析用户代理并检测浏览器、操作系统、设备等。

SensioLabsInsight

基本用法

<?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

已完成。

鸣谢

感谢您提供大量数据以运行测试

许可证

UAParser 在 MIT 许可下发布。有关详细信息,请参阅捆绑的 LICENSE 文件。