@@ -164,7 +164,7 @@ |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $version Windows number version |
|
| 167 | + * @param string $version Windows number version |
|
| 168 | 168 | * @return string Windows version |
| 169 | 169 | */ |
| 170 | 170 | private static function getWindowsVersion($version) |
@@ -53,27 +53,27 @@ discard block |
||
| 53 | 53 | * Detector constructor. |
| 54 | 54 | * @param string $pathToData Path to directory with xml data files |
| 55 | 55 | */ |
| 56 | - private function __construct($pathToData='auto') |
|
| 56 | + private function __construct($pathToData = 'auto') |
|
| 57 | 57 | { |
| 58 | - if($pathToData == 'auto') |
|
| 58 | + if ($pathToData == 'auto') |
|
| 59 | 59 | { |
| 60 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
| 60 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $xml = array('browser','device','os','robot'); |
|
| 63 | + $xml = array('browser', 'device', 'os', 'robot'); |
|
| 64 | 64 | $xmlData = array(); |
| 65 | - foreach($xml as $name) |
|
| 65 | + foreach ($xml as $name) |
|
| 66 | 66 | { |
| 67 | 67 | $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml'); |
| 68 | 68 | } |
| 69 | 69 | $this->setXmlData($xmlData); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public static function Analyse($uaString='UA',$pathToData='auto') |
|
| 72 | + public static function Analyse($uaString = 'UA', $pathToData = 'auto') |
|
| 73 | 73 | { |
| 74 | 74 | $ua = $uaString; |
| 75 | 75 | $pathXML = $pathToData; |
| 76 | - if($uaString == 'UA') |
|
| 76 | + if ($uaString == 'UA') |
|
| 77 | 77 | { |
| 78 | 78 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 79 | 79 | } |
@@ -81,21 +81,21 @@ discard block |
||
| 81 | 81 | $detector = new Detector($pathToData); |
| 82 | 82 | $xml = $detector->getXmlData(); |
| 83 | 83 | $data = array(); |
| 84 | - foreach($xml as $key => $item) |
|
| 84 | + foreach ($xml as $key => $item) |
|
| 85 | 85 | { |
| 86 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
| 86 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | $detectorResult = new DetectorResult(); |
| 90 | 90 | $detectorResult->uaString = $ua; |
| 91 | 91 | |
| 92 | - foreach($data as $key => $result) |
|
| 92 | + foreach ($data as $key => $result) |
|
| 93 | 93 | { |
| 94 | - switch($key) |
|
| 94 | + switch ($key) |
|
| 95 | 95 | { |
| 96 | 96 | case 'os': |
| 97 | 97 | $os = new OS($result); |
| 98 | - $os->Version = self::getVersion($result,$ua); |
|
| 98 | + $os->Version = self::getVersion($result, $ua); |
|
| 99 | 99 | $detectorResult->OS = $os; |
| 100 | 100 | break; |
| 101 | 101 | case 'device': |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | break; |
| 105 | 105 | case 'browser': |
| 106 | 106 | $browser = new Browser($result); |
| 107 | - $browser->Version = self::getVersion($result,$ua); |
|
| 107 | + $browser->Version = self::getVersion($result, $ua); |
|
| 108 | 108 | $detectorResult->Browser = $browser; |
| 109 | 109 | break; |
| 110 | 110 | } |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @param string $uaString User agent |
| 120 | 120 | * @return \SimpleXMLElement xml element |
| 121 | 121 | */ |
| 122 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 122 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 123 | 123 | { |
| 124 | 124 | $data = $xmlData[$key]->data; |
| 125 | - foreach($data as $xmlItem) |
|
| 125 | + foreach ($data as $xmlItem) |
|
| 126 | 126 | { |
| 127 | 127 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 128 | - if(preg_match($pattern,$uaString)) |
|
| 128 | + if (preg_match($pattern, $uaString)) |
|
| 129 | 129 | { |
| 130 | 130 | return $xmlItem; |
| 131 | 131 | } |
@@ -138,22 +138,22 @@ discard block |
||
| 138 | 138 | * @param string $uaString User agent |
| 139 | 139 | * @return string Version |
| 140 | 140 | */ |
| 141 | - private static function getVersion($xmlItem,$uaString) |
|
| 141 | + private static function getVersion($xmlItem, $uaString) |
|
| 142 | 142 | { |
| 143 | 143 | $vPattern = $xmlItem->versionPattern; |
| 144 | 144 | $version = @'/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
| 145 | - $uaString = str_replace(' NT','',$uaString); |
|
| 146 | - if(preg_match($version,$uaString)) |
|
| 145 | + $uaString = str_replace(' NT', '', $uaString); |
|
| 146 | + if (preg_match($version, $uaString)) |
|
| 147 | 147 | { |
| 148 | - preg_match($version,$uaString,$v); |
|
| 148 | + preg_match($version, $uaString, $v); |
|
| 149 | 149 | @$version = $v[0]; |
| 150 | - $version = preg_replace('/'.$vPattern.'/','',$version); |
|
| 151 | - $version = str_replace(';','',$version); |
|
| 152 | - $version = str_replace(' ','',$version); |
|
| 153 | - $version = str_replace('/','',$version); |
|
| 154 | - $version = str_replace('_','.',$version); |
|
| 150 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 151 | + $version = str_replace(';', '', $version); |
|
| 152 | + $version = str_replace(' ', '', $version); |
|
| 153 | + $version = str_replace('/', '', $version); |
|
| 154 | + $version = str_replace('_', '.', $version); |
|
| 155 | 155 | |
| 156 | - if($xmlItem->id == 'Windows') |
|
| 156 | + if ($xmlItem->id == 'Windows') |
|
| 157 | 157 | { |
| 158 | 158 | $version = self::getWindowsVersion($version); |
| 159 | 159 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($xmlData) |
| 27 | 27 | { |
| 28 | - if($xmlData != null) |
|
| 28 | + if ($xmlData != null) |
|
| 29 | 29 | { |
| 30 | 30 | foreach ($xmlData->children() as $child) { |
| 31 | 31 | switch ($child->getName()) { |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct($xmlData) |
| 23 | 23 | { |
| 24 | - if($xmlData == null) |
|
| 24 | + if ($xmlData == null) |
|
| 25 | 25 | { |
| 26 | 26 | $this->Name = 'Desktop'; |
| 27 | 27 | $this->Type = 'desktop'; |
@@ -25,8 +25,7 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $this->Name = 'Desktop'; |
| 27 | 27 | $this->Type = 'desktop'; |
| 28 | - } |
|
| 29 | - else |
|
| 28 | + } else |
|
| 30 | 29 | { |
| 31 | 30 | parent::__construct($xmlData); |
| 32 | 31 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | public function __construct($xmlData) |
| 23 | 23 | { |
| 24 | 24 | parent::__construct($xmlData); |
| 25 | - foreach($xmlData->children() as $child) |
|
| 25 | + foreach ($xmlData->children() as $child) |
|
| 26 | 26 | { |
| 27 | - switch($child->getName()) |
|
| 27 | + switch ($child->getName()) |
|
| 28 | 28 | { |
| 29 | 29 | case 'family': |
| 30 | - switch($child->__toString()) |
|
| 30 | + switch ($child->__toString()) |
|
| 31 | 31 | { |
| 32 | 32 | case 'UNX': |
| 33 | 33 | $this->Family = UNX; |
@@ -46,6 +46,6 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | -define('UNX','unix'); |
|
| 50 | -define('WIN','windows'); |
|
| 51 | -define('MAC','mac'); |
|
| 52 | 49 | \ No newline at end of file |
| 50 | +define('UNX', 'unix'); |
|
| 51 | +define('WIN', 'windows'); |
|
| 52 | +define('MAC', 'mac'); |
|
| 53 | 53 | \ No newline at end of file |