Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Added sumsung browser detection
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbull committed Dec 13, 2016
1 parent 8f2f132 commit bf61277
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 6.1.1 (released 2016-12-13)

- Added Samsung Browser detection

## 6.1.0 (released 2016-10-28)

- Fixed issue with blackberry version detection
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2016 Chris Schuld <[email protected]>
Copyright (c) 2013-2017 Chris Schuld <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The Browser class allows you to detect a user's browser and version.
* SeaMonkey
* Yandex Browser
* Comodo Dragon
* Samsung Browser

### Usage

Expand Down
9 changes: 1 addition & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"email": "[email protected]"
},
{
"name": "Chris Schuld",
"email": "[email protected]",
"homepage": "http://chrisschuld.com"
"name": "Chris Schuld"
}
],
"require": {
Expand All @@ -30,11 +28,6 @@
"Sinergi\\BrowserDetector\\Tests\\": ["tests/BrowserDetector/Tests", "tests/BrowserDetector/Tests/_includes"]
}
},
"extra": {
"branch-alias": {
"dev-develop": "6.1-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
1 change: 1 addition & 0 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Browser
const AMAYA = 'Amaya';
const LYNX = 'Lynx';
const SAFARI = 'Safari';
const SAMSUNG_BROWSER = 'SamsungBrowser';
const CHROME = 'Chrome';
const NAVIGATOR = 'Navigator';
const GOOGLEBOT = 'GoogleBot';
Expand Down
22 changes: 22 additions & 0 deletions src/BrowserDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BrowserDetector implements DetectorInterface
'SeaMonkey',
'Firefox',
'Yandex',
'Samsung',
'Chrome',
'OmniWeb',
// common mobile
Expand Down Expand Up @@ -373,6 +374,27 @@ public static function checkBrowserOpera()
return false;
}

/**
* Determine if the browser is Samsung.
*
* @return bool
*/
public static function checkBrowserSamsung()
{
if (stripos(self::$userAgentString, 'SamsungBrowser') !== false) {
$aresult = explode('/', stristr(self::$userAgentString, 'SamsungBrowser'));
if (isset($aresult[1])) {
$aversion = explode(' ', $aresult[1]);
self::$browser->setVersion($aversion[0]);
}
self::$browser->setName(Browser::SAMSUNG_BROWSER);

return true;
}

return false;
}

/**
* Determine if the browser is Chrome.
*
Expand Down
20 changes: 19 additions & 1 deletion src/DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public static function detect(Device $device, UserAgent $userAgent)
return (
self::checkIpad($device, $userAgent) ||
self::checkIphone($device, $userAgent) ||
self::checkWindowsPhone($device, $userAgent)
self::checkWindowsPhone($device, $userAgent) ||
self::checkSamsungPhone($device, $userAgent)
);
}

Expand Down Expand Up @@ -76,4 +77,21 @@ private static function checkWindowsPhone(Device $device, UserAgent $userAgent)
}
return false;
}

/**
* Determine if the device is Windows Phone.
*
* @param Device $device
* @param UserAgent $userAgent
* @return bool
*/
private static function checkSamsungPhone(Device $device, UserAgent $userAgent)
{
if (preg_match('/SAMSUNG SM-([^ ]*)/i', $userAgent->getUserAgentString(), $matches)) {
$device->setName(str_ireplace('SAMSUNG', 'Samsung', $matches[0]));
return true;
}

return false;
}
}
11 changes: 11 additions & 0 deletions tests/BrowserDetector/Tests/_files/UserAgentStrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,16 @@
Mozilla/5.0 (BlackBerry; U; BlackBerry 9380; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.523 Mobile Safari/534.11+
</field>
</string>
<string>
<field name="browser">SamsungBrowser</field>
<field name="version">3.3</field>
<field name="os">Android</field>
<field name="os_version">5.1.1</field>
<field name="device">Samsung SM-G360T1</field>
<field name="device_version">unknown</field>
<field name="string">
Mozilla/5.0 (Linux; Android 5.1.1; SAMSUNG SM-G360T1 Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.3 Chrome/38.0.2125.102 Mobile Safari/537.36
</field>
</string>
</strings>
</document>

0 comments on commit bf61277

Please sign in to comment.