Skip to content

Commit

Permalink
Merge pull request #25 from PopNatanael/3.0
Browse files Browse the repository at this point in the history
Added documentation for v3
  • Loading branch information
alexmerlin authored May 3, 2024
2 parents 8bedd59 + 9784aab commit e94c7f8
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 226 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Continuous Integration"

on:
pull_request:
push:
branches:
tags:

jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/[email protected]
47 changes: 0 additions & 47 deletions .github/workflows/cs-tests.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: docs-build

on:
release:
types: [published]
workflow_dispatch:

jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Build Docs
uses: dotkernel/documentation-theme/github-actions/docs@main
env:
DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 0 additions & 47 deletions .github/workflows/static-analysis.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/workflows/unit-tests.yml

This file was deleted.

157 changes: 74 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dot-user-agent-sniffer

DotKernel component based on [device-detector](https://github.com/matomo-org/device-detector), providing details about a device by parsing a user agent.

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-user-agent-sniffer)
Expand All @@ -9,110 +10,100 @@ DotKernel component based on [device-detector](https://github.com/matomo-org/dev
[![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/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/static-analysis.yml)
[![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)

[![SymfonyInsight](https://insight.symfony.com/projects/2e87cb23-ba35-4bef-a576-f9cb3a989ee9/big.svg)](https://insight.symfony.com/projects/2e87cb23-ba35-4bef-a576-f9cb3a989ee9)


## 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
<?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;

<?php

declare(strict_types=1);

namespace Api\Example\Service;

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

/**
* MyService constructor.
* @param DeviceServiceInterface $deviceService
* Class MyService
* @package Api\Example\Service
*/
public function __construct(DeviceServiceInterface $deviceService)
class MyService
{
$this->deviceService = $deviceService;
/** @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);
}
}

/**
* @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',
)),
))
```
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',
),
)
```
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',
),
)
Loading

0 comments on commit e94c7f8

Please sign in to comment.