Skip to content

Commit

Permalink
refs #4792 - added detection of vendor fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Jan 1, 2015
1 parent 97f587b commit b8803fb
Show file tree
Hide file tree
Showing 6 changed files with 1,021 additions and 77 deletions.
9 changes: 9 additions & 0 deletions DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use DeviceDetector\Parser\OperatingSystem;
use DeviceDetector\Parser\Client\ClientParserAbstract;
use DeviceDetector\Parser\Device\DeviceParserAbstract;
use DeviceDetector\Parser\VendorFragment;
use \Spyc;

class DeviceDetector
Expand Down Expand Up @@ -507,6 +508,14 @@ protected function parseDevice() {
}
}

/**
* If no brand has been assigned try to match by known vendor fragments
*/
if (empty($this->brand)) {
$vendorParser = new VendorFragment($this->getUserAgent());
$this->brand = $vendorParser->parse();
}

/**
* Some user agents simply contain the fragment 'Android; Tablet;', so we assume those devices as tablets
*/
Expand Down
5 changes: 5 additions & 0 deletions Parser/Device/DeviceParserAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ abstract class DeviceParserAbstract extends ParserAbstract
'CM' => 'Crius Mea',
'CR' => 'CreNova',
'CT' => 'Capitel',
'CQ' => 'Compaq',
'CO' => 'Coolpad',
'CU' => 'Cube',
'CY' => 'Coby Kyros',
Expand All @@ -108,6 +109,8 @@ abstract class DeviceParserAbstract extends ParserAbstract
'EV' => 'Evertek',
'EZ' => 'Ezze',
'FL' => 'Fly',
'FU' => 'Fujitsu',
'GA' => 'Gateway',
'GD' => 'Gemini',
'GI' => 'Gionee',
'GG' => 'Gigabyte',
Expand All @@ -120,6 +123,7 @@ abstract class DeviceParserAbstract extends ParserAbstract
'HT' => 'HTC',
'HU' => 'Huawei',
'HX' => 'Humax',
'HY' => 'Hyrican',
'IA' => 'Ikea',
'IB' => 'iBall',
'IY' => 'iBerry',
Expand Down Expand Up @@ -163,6 +167,7 @@ abstract class DeviceParserAbstract extends ParserAbstract
'MM' => 'Mpman',
'MR' => 'Motorola',
'MS' => 'Microsoft',
'MZ' => 'MSI',
'MU' => 'Memup',
'MT' => 'Mitsubishi',
'MY' => 'MyPhone',
Expand Down
36 changes: 36 additions & 0 deletions Parser/VendorFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
namespace DeviceDetector\Parser;
use DeviceDetector\Parser\Device\DeviceParserAbstract;

/**
* Class VendorFragments
*
* Device parser for vendor fragment detection
*
* @package DeviceDetector\Parser\Device
*/
class VendorFragment extends ParserAbstract
{
protected $fixtureFile = 'regexes/vendorfragments.yml';
protected $parserName = 'vendorfragments';

public function parse()
{
foreach ($this->getRegexes() as $brand => $regexes) {
foreach($regexes AS $regex) {
if ($this->matchUserAgent($regex.'[^a-z0-9]+')) {
return array_search($brand, DeviceParserAbstract::$deviceBrands);
}
}
}

return '';
}

}
Loading

0 comments on commit b8803fb

Please sign in to comment.