Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Composer
uses: php-actions/composer@v6
with:
php_version: 8.2
php_version: 8.4
php_extensions: mbstring xdebug

- name: PHPUnit Tests
Expand Down
44 changes: 22 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/agentzero.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ private function __construct(string $ua, \stdClass $data) {
// platform
$this->kernel = $data->kernel ?? null;
$this->platform = $data->platform ?? null;
$this->platformversion = $data->platformversion ?? null;
$this->platformversion = !empty($data->platformversion) ? \strval($data->platformversion) : null;

// browser
$this->engine = $data->engine ?? null;
$this->engineversion = $data->engineversion ?? null;
$this->engineversion = !empty($data->engineversion) ? \strval($data->engineversion) : null;
$this->browser = $data->browser ?? null;
$this->browserversion = $data->browserversion ?? null;
$this->browserversion = !empty($data->browserversion) ? \strval($data->browserversion) : null;
$this->browserstatus = $data->browserstatus ?? null;
$this->browserreleased = !empty($data->browserreleased) ? $data->browserreleased : null;
$this->browserlatest = $data->browserlatest ?? null;
Expand All @@ -104,9 +104,9 @@ private function __construct(string $ua, \stdClass $data) {
// app
$this->app = $data->app ?? null;
$this->appname = $data->appname ?? null;
$this->appversion = $data->appversion ?? null;
$this->appversion = !empty($data->appversion) ? \strval($data->appversion) : null;
$this->framework = $data->framework ?? null;
$this->frameworkversion = $data->frameworkversion ?? null;
$this->frameworkversion = !empty($data->frameworkversion) ? \strval($data->frameworkversion) : null;
$this->url = $data->url ?? null;

// network
Expand Down Expand Up @@ -251,7 +251,7 @@ public static function parse(string $ua, array $hints = [], array $config = [])
// lowercase the tokens
$tokenslower = [];
foreach ($tokens AS $key => $item) {
$tokenslower[$key] = $item;
$tokenslower[$key] = \mb_strtolower($item);
}

// extract UA info
Expand Down
32 changes: 26 additions & 6 deletions src/helpers/versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ protected static function released(array $data, string $version) : ?string {
return !empty($released) ? (new \DateTime(\strval($released)))->format('Y-m-d') : null;
}

protected static function legacy(array $browsers, string $version) : bool {
$earliest = \strval(\array_key_last($browsers));

// check if we have a version in range
$parts = \explode('.', $version);
foreach (\explode('.', $earliest) AS $key => $item) {
if (isset($parts[$key])) {

// older than earlier version we have a date for
if ($item > $parts[$key]) {
return true;

// newer than the earlier version we have a date for
} elseif ($item < $parts[$key]) {
return false;
}
}
}
return false;
}

public static function get(string $browser, string $version, array $config) : array {
$source = $config['versionssource'];
$cache = $config['versionscache'];
Expand All @@ -110,10 +131,13 @@ public static function get(string $browser, string $version, array $config) : ar
// check if version is greater than latest version
$major = \intval($version);
$latest = \intval($data['browserlatest']);
$first = \intval(\array_key_last($versions[$browser]));

// check if we have a version in range
if (self::legacy($versions[$browser], $version)) {
$data['browserstatus'] = 'legacy';

// version is way out of bounds (This happens sometimes, for example if the safari engine version is reported instead of the browser version)
if ($latest + 3 < $major) {
} elseif ($latest + 3 < $major) {
return [];

// nightly build?
Expand All @@ -128,10 +152,6 @@ public static function get(string $browser, string $version, array $config) : ar
} elseif ($latest + 1 === $major) {
$data['browserstatus'] = 'beta';

// so old we don't have data for it
} elseif ($major < $first) {
$data['browserstatus'] = 'legacy';

// find closes match for version
} else {

Expand Down
10 changes: 4 additions & 6 deletions tests/browsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ public function testBrave() : void {
'engine' => 'WebKit',
'engineversion' => '601.1.46',
'browser' => 'Brave',
'browserversion' => '1.2.11',
'browserreleased' => '2026-04-08'
'browserversion' => '1.2.11'
],
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Brave/115.0.0.0 Safari/605.1.15' => [
'string' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Brave/115.0.0.0 Safari/605.1.15',
Expand Down Expand Up @@ -660,8 +659,7 @@ public function testKonqueror() : void {
'platform' => 'Kubuntu',
'browser' => 'Konqueror',
'browserversion' => '3.5',
'language' => 'en-US',
'browserreleased' => '2007-12-04'
'language' => 'en-US'
],
'Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20021102)' => [
'string' => 'Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20021102)',
Expand All @@ -672,8 +670,7 @@ public function testKonqueror() : void {
'architecture' => 'x86',
'bits' => 32,
'browser' => 'Konqueror',
'browserversion' => '3.1',
'browserreleased' => '2007-12-04'
'browserversion' => '3.1'
]
];
foreach ($strings AS $ua => $item) {
Expand Down Expand Up @@ -1573,6 +1570,7 @@ public function testSilk() : void {
'bits' => 64,
'browser' => 'Silk',
'browserversion' => '148.0.5259.39',
'browserreleased' => '2026-04-23',
'engine' => 'Blink',
'engineversion' => '148.0.5259.39'
]
Expand Down
2 changes: 1 addition & 1 deletion tests/clientHintsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testClientHints() : void {
'bits' => 64,
'kernel' => 'Windows NT',
'platform' => 'Windows',
'platformversion' => '19.0.0',
'platformversion' => '11',
'engine' => 'Blink',
'engineversion' => '133.0.6943.142',
'browser' => 'Chrome',
Expand Down
Loading