rilwanfit/yauaa-php

Yet Another User Agent Analyzer โ€“ a PHP implementation

v1.0.0 2025-04-30 05:52 UTC

This package is auto-updated.

Last update: 2025-04-30 05:52:39 UTC


README

Yet Another User Agent Analyzer โ€“ PHP Edition
A lightweight and extensible PHP library for parsing and analyzing User-Agent strings, inspired by the original YAUAA (Java).

License

๐Ÿ™ Special Thanks

This project is heavily inspired by the amazing work of Niels Basjes, author of the original Yet Another UserAgent Analyzer (YAUAA).
Without YAUAA, this PHP version wouldn't exist.

๐Ÿš€ Features

  • Detect browser (agent) name and version
  • Detect layout engine [ToDo]
  • Detect operating system and version [ToDo]
  • Detect device class, brand, and name [ToDo]
  • Basic bot detection support
  • Pattern-driven and fully customizable (via YAML)
  • No external dependencies required (except Symfony YAML parser)

๐Ÿงฐ Installation

composer require rilwanfit/yauaa-php

๐Ÿงช Example Usage

use Rilwanfit\YauaaPhp\Analyzer;

$analyzer = new Analyzer(__DIR__ . '/resources/patterns.yaml');

$result = $analyzer->analyze('Mozilla/5.0 Chrome/117.0.0.0 Safari/537.36');

print_r($result);

๐Ÿ” Example Output

[
    'agent' => [
        'class' => 'Browser',
        'name' => 'Chrome',
        'version' => '117.0.0.0',
        'version_major' => '117',
        'name_version' => 'Chrome 117.0.0.0',
        'name_version_major' => 'Chrome 117'
    ],
    'layout_engine' => [ ... ],
    'os' => [ ... ],
    'device' => [ ... ]
]

๐Ÿ“ฆ Custom Patterns

Patterns are loaded from a YAML file (resources/patterns.yaml). Example format:

browsers:
  - name: "Chrome"
    class: "Browser"
    pattern: "~Chrome/(?<version>[\\d\\.]+)~i"

os:
  - name: "Windows"
    class: "Operating System"
    pattern: "~Windows NT (?<version>[\\d\\.]+)~i"

device:
  - name: "Desktop"
    class: "Desktop"
    pattern: "~Windows NT~i"

โœ… Testing

composer install
./vendor/bin/phpunit

๐Ÿงฑ Directory Structure

src/
  Analyzer.php

resources/
  patterns.yaml

tests/
  AnalyzerTest.php

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ‘จโ€๐Ÿ’ป Author

Built by Rilwan Fit