Skip to content

Commit

Permalink
Merge pull request #20 from woothee/remove_dead_code_for_ios
Browse files Browse the repository at this point in the history
Remove daed code for iOS
iPhone/iPod/iPad detection is implemented in src/AgentCategory/Os/SmartPhone.php.
So remove from src/AgentCategory/Os/Osx.php.
  • Loading branch information
yuya-takeyama committed Feb 1, 2015
2 parents 88aa4fe + d504d20 commit aa8313e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 1 addition & 11 deletions src/AgentCategory/Os/Osx.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ public static function challenge($ua, &$result)
$version = null;

if (strpos($ua, 'like Mac OS X') !== false) {
if (strpos($ua, 'iPhone;') !== false) {
$data = DataSet::get('iPhone');
} elseif (strpos($ua, 'iPad') !== false) {
$data = DataSet::get('iPad');
} elseif (strpos($ua, 'iPod') !== false) {
$data = DataSet::get('iPod');
}

if (preg_match('/; CPU(?: iPhone)? OS (\\d+_\\d+(?:_\\d+)?) like Mac OS X/', $ua, $matches) === 1) {
$version = str_replace('_', '.', $matches[1]);
}
return false;
} else {
if (preg_match('/Mac OS X (10[._]\\d+(?:[._]\\d+)?)(?:\\)|;)/', $ua, $matches) === 1) {
$version = str_replace('_', '.', $matches[1]);
Expand Down
18 changes: 14 additions & 4 deletions src/AgentCategory/Os/SmartPhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ public static function challenge($ua, &$result)
$data = null;
$version = null;

if (strpos($ua, 'iPhone') !== false) {
$data = DataSet::get('iPhone');
if (strpos($ua, 'iPod') !== false) {
$data = DataSet::get('iPod');
$version = static::parseIosVersion($ua);
} elseif (strpos($ua, 'iPad') !== false) {
$data = DataSet::get('iPad');
} elseif (strpos($ua, 'iPod') !== false) {
$data = DataSet::get('iPod');
$version = static::parseIosVersion($ua);
} elseif (strpos($ua, 'iPhone') !== false) {
$data = DataSet::get('iPhone');
$version = static::parseIosVersion($ua);
} elseif (strpos($ua, 'Android') !== false) {
$data = DataSet::get('Android');
} elseif (strpos($ua, 'CFNetwork') !== false) {
Expand Down Expand Up @@ -48,4 +51,11 @@ public static function challenge($ua, &$result)

return true;
}

private static function parseIosVersion($ua)
{
if (preg_match('/; CPU(?: iPhone)? OS (\\d+_\\d+(?:_\\d+)?) like Mac OS X/', $ua, $matches) === 1) {
return str_replace('_', '.', $matches[1]);
}
}
}

0 comments on commit aa8313e

Please sign in to comment.