承接 dotkernel/dot-user-agent-sniffer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dotkernel/dot-user-agent-sniffer

最新稳定版本:3.8.0

Composer 安装命令:

composer require dotkernel/dot-user-agent-sniffer

包简介

Dotkernel component providing details about a device by parsing a user agent.

README 文档

README

Dotkernel component based on matomo/device-detector, providing details about a device by parsing a user agent.

dotkernel/dot-user-agent-sniffer is a wrapper on top of matomo/device-detector

Documentation

Documentation is available at: https://docs.dotkernel.org/dot-user-agent-sniffer/.

Badges

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static codecov PHPStan

Install

You can install this library by running the following command:

composer require dotkernel/dot-user-agent-sniffer

Before adding this library as a dependency to your service, you need to add Dot\UserAgentSniffer\ConfigProvider::class, to your application's config/config.php file.

Usage example

<?php

declare(strict_types=1);

namespace Api\Example\Service;

use Dot\UserAgentSniffer\Data\DeviceData;
use Dot\UserAgentSniffer\Service\DeviceServiceInterface;

/**
 * Class MyService
 * @package Api\Example\Service
 */
class MyService
{
    /** @var DeviceServiceInterface $deviceService */
    protected $deviceService;

    /**
     * MyService constructor.
     * @param DeviceServiceInterface $deviceService
     */
    public function __construct(DeviceServiceInterface $deviceService)
    {
        $this->deviceService = $deviceService;
    }

    /**
     * @param string $userAgent
     * @return DeviceData
     */
    public function myMethod(string $userAgent)
    {
        return $this->deviceService->getDetails($userAgent);
    }
}

When called with an $userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/78.0.3904.84 Mobile/15E148 Safari/604.1', myMethod($userAgent) returns an object with the following structure:

Dot\UserAgentSniffer\Data\DeviceData::__set_state(array(
    'type' => 'smartphone',
    'brand' => 'Apple',
    'model' => 'iPhone',
    'isBot' => false,
    'isMobile' => true,
    'os' =>
      Dot\UserAgentSniffer\Data\OsData::__set_state(array(
        'name' => 'iOS',
        'version' => '13.2',
        'platform' => '',
    )),
    'client' =>
      Dot\UserAgentSniffer\Data\ClientData::__set_state(array(
        'type' => 'browser',
        'name' => 'Chrome Mobile iOS',
        'engine' => 'WebKit',
        'version' => '78.0',
    )),
))

The above call can also be chained as myMethod($userAgent)->getArrayCopy(), to retrieve the details as an array:

array (
    'type' => 'smartphone',
    'brand' => 'Apple',
    'model' => 'iPhone',
    'isMobile' => true,
    'isBot' => false,
    'os' =>
      array (
        'name' => 'iOS',
        'version' => '13.2',
        'platform' => '',
    ),
    'client' =>
      array (
        'type' => 'browser',
        'name' => 'Chrome Mobile iOS',
        'engine' => 'WebKit',
        'version' => '78.0',
    ),
)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-18