rilwanfit / yauaa-php
Yet Another User Agent Analyzer โ a PHP implementation
v1.0.0
2025-04-30 05:52 UTC
Requires
- php: ^8.0
- symfony/yaml: ^7.2
Requires (Dev)
- phpunit/phpunit: ^10
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).
๐ 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