Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions src/Os.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Os
const BEOS = 'BeOS';
const WINDOWS_PHONE = 'Windows Phone';
const CHROME_OS = 'Chrome OS';
const WEBOS = "webOS";

const VERSION_UNKNOWN = 'unknown';

Expand Down
41 changes: 41 additions & 0 deletions src/OsDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static function detect(Os $os, UserAgent $userAgent)
self::checkBeOS($os, $userAgent) ||
// Android before Linux
self::checkAndroid($os, $userAgent) ||
// webOS before Linux
self::checkWebOS($os, $userAgent) ||
self::checkLinux($os, $userAgent) ||
self::checkNokia($os, $userAgent) ||
self::checkBlackBerry($os, $userAgent)
Expand Down Expand Up @@ -505,4 +507,43 @@ private static function checkBeOS(Os $os, UserAgent $userAgent)

return false;
}

/**
* Determine if the user's operating system is webOS.
*
* @param Os $os
* @param UserAgent $userAgent
*
* @return bool
*/
private static function checkWebOS(Os $os, UserAgent $userAgent)
{
if (stripos($userAgent->getUserAgentString(), 'hpwOS') !== false) {
$aresult = explode('hpwOS/', $userAgent->getUserAgentString());
if (isset($aresult[1])) {
$aversion = explode(';', $aresult[1]);
$os->setVersion($aversion[0]);
} else {
$os->setVersion($os::VERSION_UNKNOWN);
}
$os->setName($os::WEBOS);
$os->setIsMobile(true);

return true;
} elseif (stripos($userAgent->getUserAgentString(), 'webOS') !== false) {
$aresult = explode('webOS/', $userAgent->getUserAgentString());
if (isset($aresult[1])) {
$aversion = explode(';', $aresult[1]);
$os->setVersion($aversion[0]);
} else {
$os->setVersion($os::VERSION_UNKNOWN);
}
$os->setName($os::WEBOS);
$os->setIsMobile(true);

return true;
}

return false;
}
}
7 changes: 7 additions & 0 deletions tests/BrowserDetector/Tests/OsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public function testBlackberry()
$this->assertSame('7.1.0.346', $os->getVersion());
}

public function testWebOS()
{
$os = new Os('Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0');
$this->assertSame(Os::WEBOS, $os->getName());
$this->assertSame('3.0.5', $os->getVersion());
}

public function testIsMobile()
{
$os = new Os('Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 640 LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Mobile Safari/537.36 Edge/14.14393');
Expand Down