@@ -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 | |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct(\SimpleXMLElement $xmlData) |
| 23 | 23 | { |
| 24 | - if($xmlData === null || $xmlData->getName() == 'null') |
|
| 24 | + if ($xmlData === null || $xmlData->getName() == 'null') |
|
| 25 | 25 | { |
| 26 | 26 | parent::__construct($xmlData); |
| 27 | 27 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function __construct(\SimpleXMLElement $xmlData) |
| 23 | 23 | { |
| 24 | 24 | parent::__construct($xmlData); |
| 25 | - if($xmlData !== null) |
|
| 25 | + if ($xmlData !== null) |
|
| 26 | 26 | { |
| 27 | 27 | foreach ($xmlData->children() as $child) { |
| 28 | 28 | switch ($child->getName()) { |
@@ -46,6 +46,6 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | -define('UNX','unix'); |
|
| 50 | -define('WIN','windows'); |
|
| 51 | -define('MC','mac'); |
|
| 49 | +define('UNX', 'unix'); |
|
| 50 | +define('WIN', 'windows'); |
|
| 51 | +define('MC', 'mac'); |
|
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | { |
| 73 | 73 | parent::__construct($xmlData); |
| 74 | 74 | |
| 75 | - if($xmlData !== null) |
|
| 75 | + if ($xmlData !== null) |
|
| 76 | 76 | { |
| 77 | 77 | foreach ($xmlData->children() as $child) |
| 78 | 78 | { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | parent::__construct($xmlData); |
| 74 | 74 | |
| 75 | - if($xmlData !== null) |
|
| 75 | + if ($xmlData !== null) |
|
| 76 | 76 | { |
| 77 | 77 | foreach ($xmlData->children() as $child) |
| 78 | 78 | { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | break; |
| 87 | 87 | case 'isse': |
| 88 | 88 | $val = $child->__toString(); |
| 89 | - if($val == 'true') |
|
| 89 | + if ($val == 'true') |
|
| 90 | 90 | { |
| 91 | 91 | $this->setSearchEngine(true); |
| 92 | 92 | } |
@@ -89,9 +89,9 @@ |
||
| 89 | 89 | if($val == 'true') |
| 90 | 90 | { |
| 91 | 91 | $this->setSearchEngine(true); |
| 92 | + } else { |
|
| 93 | + $this->setSearchEngine(false); |
|
| 92 | 94 | } |
| 93 | - else |
|
| 94 | - $this->setSearchEngine(false); |
|
| 95 | 95 | break; |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | public function __construct(\SimpleXMLElement $xmlData) |
| 106 | 106 | { |
| 107 | - if($xmlData !== null) |
|
| 107 | + if ($xmlData !== null) |
|
| 108 | 108 | { |
| 109 | 109 | foreach ($xmlData->children() as $child) { |
| 110 | 110 | switch ($child->getName()) |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | break; |
| 124 | 124 | case 'targetProperty': |
| 125 | 125 | $boolVal = $child->__toString(); |
| 126 | - if($boolVal == 'true') |
|
| 126 | + if ($boolVal == 'true') |
|
| 127 | 127 | { |
| 128 | 128 | $this->TargetValue = true; |
| 129 | 129 | } |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public static function loadRulesFromFile() |
| 144 | 144 | { |
| 145 | - $path = str_replace('src','data',__DIR__).'/rules/'; |
|
| 145 | + $path = str_replace('src', 'data', __DIR__).'/rules/'; |
|
| 146 | 146 | $files = scandir($path); |
| 147 | 147 | $rules = array(); |
| 148 | - foreach($files as $file) |
|
| 148 | + foreach ($files as $file) |
|
| 149 | 149 | { |
| 150 | - if($file != '.' && $file != '..') |
|
| 150 | + if ($file != '.' && $file != '..') |
|
| 151 | 151 | { |
| 152 | 152 | $xmlObj = simplexml_load_file($path.$file); |
| 153 | - foreach($xmlObj->children() as $rule) |
|
| 153 | + foreach ($xmlObj->children() as $rule) |
|
| 154 | 154 | { |
| 155 | 155 | $rules[] = new self($rule); |
| 156 | 156 | } |
@@ -126,8 +126,7 @@ |
||
| 126 | 126 | if($boolVal == 'true') |
| 127 | 127 | { |
| 128 | 128 | $this->TargetValue = true; |
| 129 | - } |
|
| 130 | - else |
|
| 129 | + } else |
|
| 131 | 130 | { |
| 132 | 131 | $this->TargetValue = false; |
| 133 | 132 | } |
@@ -117,8 +117,7 @@ discard block |
||
| 117 | 117 | $os = new OS($result); |
| 118 | 118 | $os->setVersion(self::getVersion($result, $ua)); |
| 119 | 119 | $detectorResult->OS = $os; |
| 120 | - } |
|
| 121 | - else |
|
| 120 | + } else |
|
| 122 | 121 | { |
| 123 | 122 | $os = OS::initEmpty(); |
| 124 | 123 | $detectorResult->OS = $os; |
@@ -129,8 +128,7 @@ discard block |
||
| 129 | 128 | { |
| 130 | 129 | $device = new Device($result); |
| 131 | 130 | $detectorResult->Device = $device; |
| 132 | - } |
|
| 133 | - else |
|
| 131 | + } else |
|
| 134 | 132 | { |
| 135 | 133 | $device = Device::initEmpty(); |
| 136 | 134 | $detectorResult->Device = $device; |
@@ -142,8 +140,7 @@ discard block |
||
| 142 | 140 | $browser = new Browser($result); |
| 143 | 141 | $browser->setVersion(self::getVersion($result, $ua)); |
| 144 | 142 | $detectorResult->Browser = $browser; |
| 145 | - } |
|
| 146 | - else |
|
| 143 | + } else |
|
| 147 | 144 | { |
| 148 | 145 | $browser = Browser::initEmpty(); |
| 149 | 146 | $detectorResult->Browser = $browser; |
@@ -52,26 +52,26 @@ discard block |
||
| 52 | 52 | * Detector constructor. |
| 53 | 53 | * @param string $pathToData Path to directory with xml data files |
| 54 | 54 | */ |
| 55 | - private function __construct($pathToData='auto') |
|
| 55 | + private function __construct($pathToData = 'auto') |
|
| 56 | 56 | { |
| 57 | - if($pathToData == 'auto') |
|
| 57 | + if ($pathToData == 'auto') |
|
| 58 | 58 | { |
| 59 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
| 59 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $xml = array('robot','browser','device','os'); |
|
| 62 | + $xml = array('robot', 'browser', 'device', 'os'); |
|
| 63 | 63 | $xmlData = array(); |
| 64 | - foreach($xml as $name) |
|
| 64 | + foreach ($xml as $name) |
|
| 65 | 65 | { |
| 66 | 66 | $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml'); |
| 67 | 67 | } |
| 68 | 68 | $this->setXmlData($xmlData); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public static function analyse($uaString='UA', $pathToData='auto') |
|
| 71 | + public static function analyse($uaString = 'UA', $pathToData = 'auto') |
|
| 72 | 72 | { |
| 73 | 73 | $ua = $uaString; |
| 74 | - if($uaString == 'UA') |
|
| 74 | + if ($uaString == 'UA') |
|
| 75 | 75 | { |
| 76 | 76 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 77 | 77 | } |
@@ -79,23 +79,23 @@ discard block |
||
| 79 | 79 | $detector = new Detector($pathToData); |
| 80 | 80 | $xml = $detector->getXmlData(); |
| 81 | 81 | $data = array(); |
| 82 | - foreach($xml as $key => $item) |
|
| 82 | + foreach ($xml as $key => $item) |
|
| 83 | 83 | { |
| 84 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
| 84 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $detectorResult = new DetectorResult(); |
| 88 | 88 | $detectorResult->uaString = $ua; |
| 89 | 89 | $isRobot = false; |
| 90 | 90 | |
| 91 | - foreach($data as $key => $result) |
|
| 91 | + foreach ($data as $key => $result) |
|
| 92 | 92 | { |
| 93 | - if(!$isRobot) |
|
| 93 | + if (!$isRobot) |
|
| 94 | 94 | { |
| 95 | 95 | switch ($key) |
| 96 | 96 | { |
| 97 | 97 | case 'robot': |
| 98 | - if($result !== null) |
|
| 98 | + if ($result !== null) |
|
| 99 | 99 | { |
| 100 | 100 | $robot = new Robot($result); |
| 101 | 101 | $detectorResult->Robot = $robot; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | break; |
| 107 | 107 | case 'os': |
| 108 | - if($result !== null) |
|
| 108 | + if ($result !== null) |
|
| 109 | 109 | { |
| 110 | 110 | $os = new OS($result); |
| 111 | 111 | $os->setVersion(self::getVersion($result, $ua)); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | break; |
| 120 | 120 | case 'device': |
| 121 | - if($result !== null) |
|
| 121 | + if ($result !== null) |
|
| 122 | 122 | { |
| 123 | 123 | $device = new Device($result); |
| 124 | 124 | $detectorResult->Device = $device; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | break; |
| 132 | 132 | case 'browser': |
| 133 | - if($result !== null) |
|
| 133 | + if ($result !== null) |
|
| 134 | 134 | { |
| 135 | 135 | $browser = new Browser($result); |
| 136 | 136 | $browser->setVersion(self::getVersion($result, $ua)); |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | * @param string $uaString User agent |
| 158 | 158 | * @return \SimpleXMLElement xml element |
| 159 | 159 | */ |
| 160 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 160 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 161 | 161 | { |
| 162 | 162 | $data = $xmlData[$key]->data; |
| 163 | - foreach($data as $xmlItem) |
|
| 163 | + foreach ($data as $xmlItem) |
|
| 164 | 164 | { |
| 165 | 165 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 166 | - if(preg_match($pattern,$uaString)) |
|
| 166 | + if (preg_match($pattern, $uaString)) |
|
| 167 | 167 | { |
| 168 | 168 | return $xmlItem; |
| 169 | 169 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * @param string $uaString User agent |
| 177 | 177 | * @return string Version |
| 178 | 178 | */ |
| 179 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 179 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 180 | 180 | { |
| 181 | - if($xmlItem !== null) |
|
| 181 | + if ($xmlItem !== null) |
|
| 182 | 182 | { |
| 183 | - foreach($xmlItem->children() as $node) |
|
| 183 | + foreach ($xmlItem->children() as $node) |
|
| 184 | 184 | { |
| 185 | - if($node->getName() == 'versionPattern') |
|
| 185 | + if ($node->getName() == 'versionPattern') |
|
| 186 | 186 | { |
| 187 | 187 | $vPattern = $node->__toString(); |
| 188 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 188 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 189 | 189 | $uaString = str_replace(' NT', '', $uaString); |
| 190 | 190 | if (preg_match($version, $uaString)) { |
| 191 | 191 | preg_match($version, $uaString, $v); |
| 192 | 192 | $version = $v[0]; |
| 193 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 193 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 194 | 194 | $version = str_replace(';', '', $version); |
| 195 | 195 | $version = str_replace(' ', '', $version); |
| 196 | 196 | $version = str_replace('/', '', $version); |
@@ -234,14 +234,14 @@ discard block |
||
| 234 | 234 | private static function checkRules(DetectorResult $result) |
| 235 | 235 | { |
| 236 | 236 | $Rules = DetectorRule::loadRulesFromFile(); |
| 237 | - foreach($Rules as $rule) |
|
| 237 | + foreach ($Rules as $rule) |
|
| 238 | 238 | { |
| 239 | 239 | $objectType = $rule->getObjectType(); |
| 240 | 240 | $objectProperty = $rule->getObjectProperty(); |
| 241 | 241 | $targetType = $rule->getTargetType(); |
| 242 | 242 | $targetValue = $rule->isTargetValue(); |
| 243 | 243 | $func = 'get'.$objectProperty; |
| 244 | - if($result->$objectType !== null) |
|
| 244 | + if ($result->$objectType !== null) |
|
| 245 | 245 | { |
| 246 | 246 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 247 | 247 | $result->$targetType = $targetValue; |
@@ -252,4 +252,4 @@ discard block |
||
| 252 | 252 | return $result; |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | -define('D_NA','N\A'); |
|
| 255 | +define('D_NA', 'N\A'); |
|