@@ -56,7 +56,7 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | public function __construct(\SimpleXMLElement $xmlData) |
| 58 | 58 | { |
| 59 | - if($xmlData !== null) |
|
| 59 | + if ($xmlData !== null) |
|
| 60 | 60 | { |
| 61 | 61 | foreach ($xmlData->children() as $child) { |
| 62 | 62 | switch ($child->getName()) { |
@@ -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'); |
|
@@ -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 | |
@@ -43,8 +43,7 @@ |
||
| 43 | 43 | |
| 44 | 44 | $this->setName('Desktop'); |
| 45 | 45 | $this->setType('desktop'); |
| 46 | - } |
|
| 47 | - else |
|
| 46 | + } else |
|
| 48 | 47 | { |
| 49 | 48 | parent::__construct($xmlData); |
| 50 | 49 | |
@@ -72,19 +72,19 @@ |
||
| 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 | { |
| 79 | 79 | $name = $child->getName(); |
| 80 | 80 | $val = $child->__toString(); |
| 81 | - if($name != 'id' && $name != 'pattern' && $name != 'SearchEngine') |
|
| 81 | + if ($name != 'id' && $name != 'pattern' && $name != 'SearchEngine') |
|
| 82 | 82 | { |
| 83 | 83 | $this->$name = $val; |
| 84 | 84 | } |
| 85 | - if($name == 'SearchEngine') |
|
| 85 | + if ($name == 'SearchEngine') |
|
| 86 | 86 | { |
| 87 | - if($val == 'true') |
|
| 87 | + if ($val == 'true') |
|
| 88 | 88 | { |
| 89 | 89 | $this->setSearchEngine(true); |
| 90 | 90 | } |
@@ -87,9 +87,9 @@ |
||
| 87 | 87 | if($val == 'true') |
| 88 | 88 | { |
| 89 | 89 | $this->setSearchEngine(true); |
| 90 | + } else { |
|
| 91 | + $this->setSearchEngine(false); |
|
| 90 | 92 | } |
| 91 | - else |
|
| 92 | - $this->setSearchEngine(false); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -104,13 +104,13 @@ 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 | { |
| 111 | 111 | $name = $child->getName(); |
| 112 | 112 | $val = $child->__toString(); |
| 113 | - if($name != 'TargetValue') |
|
| 113 | + if ($name != 'TargetValue') |
|
| 114 | 114 | { |
| 115 | 115 | $this->$name = $val; |
| 116 | 116 | } |
@@ -125,15 +125,15 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public static function loadRulesFromFile() |
| 127 | 127 | { |
| 128 | - $path = str_replace('src','data',__DIR__).'/rules/'; |
|
| 128 | + $path = str_replace('src', 'data', __DIR__).'/rules/'; |
|
| 129 | 129 | $files = scandir($path); |
| 130 | 130 | $rules = array(); |
| 131 | - foreach($files as $file) |
|
| 131 | + foreach ($files as $file) |
|
| 132 | 132 | { |
| 133 | - if($file != '.' && $file != '..') |
|
| 133 | + if ($file != '.' && $file != '..') |
|
| 134 | 134 | { |
| 135 | 135 | $xmlObj = simplexml_load_file($path.$file); |
| 136 | - foreach($xmlObj->children() as $rule) |
|
| 136 | + foreach ($xmlObj->children() as $rule) |
|
| 137 | 137 | { |
| 138 | 138 | $rules[] = new self($rule); |
| 139 | 139 | } |
@@ -113,9 +113,9 @@ |
||
| 113 | 113 | if($name != 'TargetValue') |
| 114 | 114 | { |
| 115 | 115 | $this->$name = $val; |
| 116 | + } else { |
|
| 117 | + $this->$name = filter_var($val, FILTER_VALIDATE_BOOLEAN); |
|
| 116 | 118 | } |
| 117 | - else |
|
| 118 | - $this->$name = filter_var($val, FILTER_VALIDATE_BOOLEAN); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function __construct(\SimpleXMLElement $xmlData) |
| 70 | 70 | { |
| 71 | - if($xmlData !== null) |
|
| 71 | + if ($xmlData !== null) |
|
| 72 | 72 | { |
| 73 | 73 | foreach ($xmlData->children() as $child) |
| 74 | 74 | { |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public static function loadFromFile() |
| 86 | 86 | { |
| 87 | - $path = str_replace('src','data',__DIR__).'/deviceModels.xml'; |
|
| 87 | + $path = str_replace('src', 'data', __DIR__).'/deviceModels.xml'; |
|
| 88 | 88 | $models = array(); |
| 89 | 89 | $xmlObj = simplexml_load_file($path); |
| 90 | - foreach($xmlObj->children() as $rule) |
|
| 90 | + foreach ($xmlObj->children() as $rule) |
|
| 91 | 91 | { |
| 92 | 92 | $models[] = new self($rule); |
| 93 | 93 | } |
@@ -42,8 +42,9 @@ discard block |
||
| 42 | 42 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if(!self::$isInitialized) |
|
| 46 | - self::initialize(); |
|
| 45 | + if(!self::$isInitialized) { |
|
| 46 | + self::initialize(); |
|
| 47 | + } |
|
| 47 | 48 | $xml = self::$_xmlData; |
| 48 | 49 | |
| 49 | 50 | $detectorResult = new DetectorResult(); |
@@ -68,8 +69,7 @@ discard block |
||
| 68 | 69 | $detectorResult->isBot = true; |
| 69 | 70 | } |
| 70 | 71 | } |
| 71 | - } |
|
| 72 | - else |
|
| 72 | + } else |
|
| 73 | 73 | { |
| 74 | 74 | $object = $classname::initEmpty(); |
| 75 | 75 | } |
@@ -163,10 +163,11 @@ discard block |
||
| 163 | 163 | '10.0' => '10' |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - if(array_key_exists(strval($version),$versions)) |
|
| 167 | - return $versions[strval($version)]; |
|
| 168 | - else |
|
| 169 | - return D_NA; |
|
| 166 | + if(array_key_exists(strval($version),$versions)) { |
|
| 167 | + return $versions[strval($version)]; |
|
| 168 | + } else { |
|
| 169 | + return D_NA; |
|
| 170 | + } |
|
| 170 | 171 | } |
| 171 | 172 | |
| 172 | 173 | /** |
@@ -21,14 +21,14 @@ discard block |
||
| 21 | 21 | private static function initialize($pathToData = 'auto') |
| 22 | 22 | { |
| 23 | 23 | if ($pathToData == 'auto') { |
| 24 | - $pathToData = str_replace('src', 'data', __DIR__) . '/'; |
|
| 24 | + $pathToData = str_replace('src', 'data', __DIR__).'/'; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | if (self::$_xmlData === null) { |
| 28 | 28 | $xml = array('Robot', 'Browser', 'Device', 'OS'); |
| 29 | 29 | $xmlData = array(); |
| 30 | 30 | foreach ($xml as $name) { |
| 31 | - $xmlData[$name] = simplexml_load_file($pathToData . strtolower($name) . '.xml'); |
|
| 31 | + $xmlData[$name] = simplexml_load_file($pathToData.strtolower($name).'.xml'); |
|
| 32 | 32 | } |
| 33 | 33 | self::$_xmlData = $xmlData; |
| 34 | 34 | self::$isInitialized = true; |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | $fields = array('OS'); |
| 41 | 41 | self::$_ymlData = []; |
| 42 | 42 | foreach ($fields as $name) { |
| 43 | - self::$_ymlData[$name] = $parser->parse(file_get_contents($pathToData . strtolower($name) . '.yml')); |
|
| 43 | + self::$_ymlData[$name] = $parser->parse(file_get_contents($pathToData.strtolower($name).'.yml')); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function analyse($uaString='UA') |
|
| 48 | + public static function analyse($uaString = 'UA') |
|
| 49 | 49 | { |
| 50 | 50 | $ua = $uaString; |
| 51 | - if($uaString == 'UA') |
|
| 51 | + if ($uaString == 'UA') |
|
| 52 | 52 | { |
| 53 | 53 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if(!self::$isInitialized) |
|
| 56 | + if (!self::$isInitialized) |
|
| 57 | 57 | self::initialize(); |
| 58 | 58 | $xml = self::$_xmlData; |
| 59 | 59 | |
@@ -61,20 +61,20 @@ discard block |
||
| 61 | 61 | $detectorResult->uaString = $ua; |
| 62 | 62 | $ns = '\\EndorphinStudio\\Detector\\'; |
| 63 | 63 | |
| 64 | - foreach($xml as $key => $item) |
|
| 64 | + foreach ($xml as $key => $item) |
|
| 65 | 65 | { |
| 66 | - $data = self::analysePart($xml,$key,$ua); |
|
| 66 | + $data = self::analysePart($xml, $key, $ua); |
|
| 67 | 67 | $classname = $ns.$key; |
| 68 | - if($data !== null) |
|
| 68 | + if ($data !== null) |
|
| 69 | 69 | { |
| 70 | 70 | $object = new $classname($data); |
| 71 | - if($key == 'OS' || $key == 'Browser') |
|
| 71 | + if ($key == 'OS' || $key == 'Browser') |
|
| 72 | 72 | { |
| 73 | 73 | $object->setVersion(self::getVersion($data, $ua)); |
| 74 | 74 | } |
| 75 | - if($key == 'Robot') |
|
| 75 | + if ($key == 'Robot') |
|
| 76 | 76 | { |
| 77 | - if($object->getName() != D_NA) |
|
| 77 | + if ($object->getName() != D_NA) |
|
| 78 | 78 | { |
| 79 | 79 | $detectorResult->isBot = true; |
| 80 | 80 | } |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | * @param string $uaString User agent |
| 100 | 100 | * @return \SimpleXMLElement xml element |
| 101 | 101 | */ |
| 102 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 102 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 103 | 103 | { |
| 104 | 104 | $data = $xmlData[$key]->data; |
| 105 | - foreach($data as $xmlItem) |
|
| 105 | + foreach ($data as $xmlItem) |
|
| 106 | 106 | { |
| 107 | 107 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 108 | - if(preg_match($pattern,$uaString)) |
|
| 108 | + if (preg_match($pattern, $uaString)) |
|
| 109 | 109 | { |
| 110 | 110 | return $xmlItem; |
| 111 | 111 | } |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | * @param string $uaString User agent |
| 119 | 119 | * @return string Version |
| 120 | 120 | */ |
| 121 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 121 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 122 | 122 | { |
| 123 | - if($xmlItem !== null) |
|
| 123 | + if ($xmlItem !== null) |
|
| 124 | 124 | { |
| 125 | - foreach($xmlItem->children() as $node) |
|
| 125 | + foreach ($xmlItem->children() as $node) |
|
| 126 | 126 | { |
| 127 | - if($node->getName() == 'versionPattern') |
|
| 127 | + if ($node->getName() == 'versionPattern') |
|
| 128 | 128 | { |
| 129 | 129 | $vPattern = $node->__toString(); |
| 130 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 130 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 131 | 131 | $uaString = str_replace(' NT', '', $uaString); |
| 132 | 132 | if (preg_match($version, $uaString)) { |
| 133 | 133 | preg_match($version, $uaString, $v); |
| 134 | 134 | $version = $v[0]; |
| 135 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 135 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 136 | 136 | $version = str_replace(';', '', $version); |
| 137 | 137 | $version = str_replace(' ', '', $version); |
| 138 | 138 | $version = str_replace('/', '', $version); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | '10.0' => '10' |
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | - if(array_key_exists(strval($version),$versions)) |
|
| 177 | + if (array_key_exists(strval($version), $versions)) |
|
| 178 | 178 | return $versions[strval($version)]; |
| 179 | 179 | else |
| 180 | 180 | return D_NA; |
@@ -187,14 +187,14 @@ discard block |
||
| 187 | 187 | private static function checkRules(DetectorResult $result) |
| 188 | 188 | { |
| 189 | 189 | $Rules = DetectorRule::loadRulesFromFile(); |
| 190 | - foreach($Rules as $rule) |
|
| 190 | + foreach ($Rules as $rule) |
|
| 191 | 191 | { |
| 192 | 192 | $objectType = $rule->getObjectType(); |
| 193 | 193 | $objectProperty = $rule->getObjectProperty(); |
| 194 | 194 | $targetType = $rule->getTargetType(); |
| 195 | 195 | $targetValue = $rule->isTargetValue(); |
| 196 | 196 | $func = 'get'.$objectProperty; |
| 197 | - if($result->$objectType !== null) |
|
| 197 | + if ($result->$objectType !== null) |
|
| 198 | 198 | { |
| 199 | 199 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 200 | 200 | $result->$targetType = $targetValue; |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | private static function checkModelName(DetectorResult $result) |
| 209 | 209 | { |
| 210 | 210 | $models = DeviceModel::loadFromFile(); |
| 211 | - foreach($models as $model) |
|
| 211 | + foreach ($models as $model) |
|
| 212 | 212 | { |
| 213 | - if($model->getDeviceName() === $result->Device->getName()) |
|
| 213 | + if ($model->getDeviceName() === $result->Device->getName()) |
|
| 214 | 214 | { |
| 215 | 215 | $pattern = '/'.$model->getPattern().'/'; |
| 216 | - preg_match($pattern,$result->uaString,$match); |
|
| 216 | + preg_match($pattern, $result->uaString, $match); |
|
| 217 | 217 | $result->Device->setModelName($match[1]); |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | return $result; |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | -define('D_NA','N\A'); |
|
| 223 | +define('D_NA', 'N\A'); |
|