An open API service indexing awesome lists of open source software.

https://github.com/dotkernel/dot-user-agent-sniffer

DotKernel component providing details about a device by parsing a user agent.
https://github.com/dotkernel/dot-user-agent-sniffer

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# dot-user-agent-sniffer

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](https://github.com/matomo-org/device-detector)

## Documentation

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

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-user-agent-sniffer)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-user-agent-sniffer/3.7.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-user-agent-sniffer)](https://github.com/dotkernel/dot-user-agent-sniffer/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-user-agent-sniffer)](https://github.com/dotkernel/dot-user-agent-sniffer/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-user-agent-sniffer)](https://github.com/dotkernel/dot-user-agent-sniffer/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-user-agent-sniffer)](https://github.com/dotkernel/dot-user-agent-sniffer/blob/3.0/LICENSE)

[![Build Static](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-user-agent-sniffer/graph/badge.svg?token=HZKFRQWDSV)](https://codecov.io/gh/dotkernel/dot-user-agent-sniffer)
[![PHPStan](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/static-analysis.yml)

## Install

You can install this library by running the following command:

```shell
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
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:

```php
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:

```php
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',
),
)
```