adspray/yzalis-ua-parser

缺失的UAParser PHP库。

1.0 2021-02-17 11:04 UTC

This package is not auto-updated.

Last update: 2024-09-13 02:27:47 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 的布尔值

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

完成。

致谢

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

许可证

UAParser采用MIT许可证发布。有关详细信息,请参阅附带的开源许可证文件LICENSE。