vietstars/client-detect 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vietstars/client-detect

最新稳定版本:v0.0.4

Composer 安装命令:

composer require vietstars/client-detect

包简介

Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

README 文档

README

Installation

Install using composer:

composer require vietstars/client-detect

Laravel (optional)

Add the service provider in config/app.php:

Vietstars\ClientDetect\ClientServiceProvider::class,

And add the Client alias to config/app.php:

'Client' => Vietstars\ClientDetect\Facades\Client::class,

Basic Usage

Start by creating an Client instance (or use the Client Facade if you are using Laravel):

use Vietstars\ClientDetect\Client;

$client = new Client();

If you want to parse user agents other than the current request in CLI scripts for example, you can use the setUserAgent and setHttpHeaders methods:

$client->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2');
$client->setHttpHeaders($headers);

All of the original Mobile Detect methods are still available, check out some original examples at https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples

Is?

Check for a certain property in the user agent.

$client->is('Windows');
$client->is('Firefox');
$client->is('iPhone');
$client->is('OS X');

Magic is-method

Magic method that does the same as the previous is() method:

$client->isAndroidOS();
$client->isNexus();
$client->isSafari();

Mobile detection

Check for mobile device:

$client->isMobile();
$client->isTablet();

Match user agent

Search the user agent with a regular expression:

$client->match('regexp');

Additional Functionality

Accept languages

Get the browser's accept languages. Example:

$languages = $client->languages();
// ['nl-nl', 'nl', 'en-us', 'en']

Device name

Get the device name, if mobile. (iPhone, Nexus, AsusTablet, ...)

$device = $client->device();

Operating system name

Get the operating system. (Ubuntu, Windows, OS X, ...)

$platform = $client->platform();

Browser name

Get the browser name. (Chrome, IE, Safari, Firefox, ...)

$browser = $client->browser();

Desktop detection

Check if the user is using a desktop device.

$client->isDesktop();

This checks if a user is not a mobile device, tablet or robot.

Phone detection

Check if the user is using a phone device.

$client->isPhone();

Robot detection

Check if the user is a robot. This uses jaybizzle/crawler-detect to do the actual robot detection.

$client->isRobot();

Robot name

Get the robot name.

$robot = $client->robot();

Browser/platform version

MobileDetect recently added a version method that can get the version number for components. To get the browser or platform version you can use:

$browser = $client->browser();
$version = $client->version($browser);

$platform = $client->platform();
$version = $client->version($platform);

Note, the version method is still in beta, so it might not return the correct result.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-18