定制 kwenziwa/devicedetector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kwenziwa/devicedetector

最新稳定版本:1.0.1

Composer 安装命令:

composer require kwenziwa/devicedetector

包简介

Device Detector is a versatile, easy-to-use package for project that provides seamless device and operating system detection. Leveraging the robustness of mobiledetect/mobiledetectlib, this package allows developers to quickly identify whether a user is accessing their application from a mobile dev

README 文档

README

Device Detector is a convenient package for applications, offering easy detection of user devices and their operating systems. Utilizing the mobiledetect/mobiledetectlib library, this package enables applications to quickly identify device types (mobile, tablet, desktop) and operating systems (iOS, Android, etc.), enhancing the user experience and providing valuable insights.

Features

  • Detect whether the user's device is a mobile, tablet, or desktop
  • Identify the operating system of the user's device (iOS, Android, etc.)
  • Lightweight and easy to integrate into any project

Installation

Install the package via composer:

composer require kwenziwa/devicedetector

Usage

After installation, you can use the DeviceDetector in your application as follows:

use Kwenziwa\DeviceDetector\DeviceDetector;

$deviceDetector = app(DeviceDetector::class);

if ($deviceDetector->isMobile()) {
    // Handle mobile device
}

if ($deviceDetector->isTablet()) {
    // Handle tablet device
}

if ($deviceDetector->isDesktop()) {
    // Handle desktop device
}

Methods

isMobile()

Determines if the user's device is a mobile phone.

$deviceDetector->isMobile();

isTablet()

Determines if the user's device is a tablet.

$deviceDetector->isTablet();

isDesktop()

Determines if the user's device is a desktop. This is typically the default if the device is neither a mobile nor a tablet.

$deviceDetector->isDesktop();

isIOS()

Checks if the user's device is running iOS.

$deviceDetector->isIOS();

isAndroidOS()

Checks if the user's device is running Android OS.

$deviceDetector->isAndroidOS();

getDeviceType()

Returns the type of the user's device as a string ('mobile', 'tablet', or 'desktop').

$deviceType = $deviceDetector->getDeviceType();

getOSType()

Returns the operating system of the user's device as a string (e.g., 'iOS', 'Android', 'Windows Mobile', 'BlackBerry', 'Symbian', or 'Unknown').

$osType = $deviceDetector->getOSType();

getBrowser()

Returns the the browser name system of the user's device as a string.

$detector = new DeviceDetector();

$browser = $detector->getBrowser();
echo "Browser: $browser";

Run the Tests

Run the tests using the PHPUnit command:

./vendor/bin/phpunit

This command will execute all tests in your tests directory. The above tests are basic and might not effectively cover all scenarios since the actual device type and OS will depend on the environment where the tests are run. In a more comprehensive test suite, you would mock the MobileDetect class to simulate different devices and operating systems. This would allow you to test all branches of your code.

Contributing

Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.

License

The Device Detector is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-28