@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | if ($pathToData == 'auto') |
| 21 | 21 | { |
| 22 | - $pathToData = str_replace('src', 'data', __DIR__) . '/'; |
|
| 22 | + $pathToData = str_replace('src', 'data', __DIR__).'/'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (self::$_xmlData === null) |
@@ -27,22 +27,22 @@ discard block |
||
| 27 | 27 | $xml = array('Robot', 'Browser', 'Device', 'OS'); |
| 28 | 28 | $xmlData = array(); |
| 29 | 29 | foreach ($xml as $name) { |
| 30 | - $xmlData[$name] = simplexml_load_file($pathToData . strtolower($name) . '.xml'); |
|
| 30 | + $xmlData[$name] = simplexml_load_file($pathToData.strtolower($name).'.xml'); |
|
| 31 | 31 | } |
| 32 | 32 | self::$_xmlData = $xmlData; |
| 33 | 33 | self::$isInitialized = true; |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public static function analyse($uaString='UA') |
|
| 37 | + public static function analyse($uaString = 'UA') |
|
| 38 | 38 | { |
| 39 | 39 | $ua = $uaString; |
| 40 | - if($uaString == 'UA') |
|
| 40 | + if ($uaString == 'UA') |
|
| 41 | 41 | { |
| 42 | 42 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if(!self::$isInitialized) |
|
| 45 | + if (!self::$isInitialized) |
|
| 46 | 46 | self::initialize(); |
| 47 | 47 | $xml = self::$_xmlData; |
| 48 | 48 | |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | $detectorResult->uaString = $ua; |
| 51 | 51 | $ns = '\\EndorphinStudio\\Detector\\'; |
| 52 | 52 | |
| 53 | - foreach($xml as $key => $item) |
|
| 53 | + foreach ($xml as $key => $item) |
|
| 54 | 54 | { |
| 55 | - $data = self::analysePart($xml,$key,$ua); |
|
| 55 | + $data = self::analysePart($xml, $key, $ua); |
|
| 56 | 56 | $classname = $ns.$key; |
| 57 | - if($data !== null) |
|
| 57 | + if ($data !== null) |
|
| 58 | 58 | { |
| 59 | 59 | $object = new $classname($data); |
| 60 | - if($key == 'OS' || $key == 'Browser') |
|
| 60 | + if ($key == 'OS' || $key == 'Browser') |
|
| 61 | 61 | { |
| 62 | 62 | $object->setVersion(self::getVersion($data, $ua)); |
| 63 | 63 | } |
| 64 | - if($key == 'Robot') |
|
| 64 | + if ($key == 'Robot') |
|
| 65 | 65 | { |
| 66 | - if($object->getName() != D_NA) |
|
| 66 | + if ($object->getName() != D_NA) |
|
| 67 | 67 | { |
| 68 | 68 | $detectorResult->isBot = true; |
| 69 | 69 | } |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @param string $uaString User agent |
| 89 | 89 | * @return \SimpleXMLElement xml element |
| 90 | 90 | */ |
| 91 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 91 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 92 | 92 | { |
| 93 | 93 | $data = $xmlData[$key]->data; |
| 94 | - foreach($data as $xmlItem) |
|
| 94 | + foreach ($data as $xmlItem) |
|
| 95 | 95 | { |
| 96 | 96 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 97 | - if(preg_match($pattern,$uaString)) |
|
| 97 | + if (preg_match($pattern, $uaString)) |
|
| 98 | 98 | { |
| 99 | 99 | return $xmlItem; |
| 100 | 100 | } |
@@ -107,21 +107,21 @@ discard block |
||
| 107 | 107 | * @param string $uaString User agent |
| 108 | 108 | * @return string Version |
| 109 | 109 | */ |
| 110 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 110 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 111 | 111 | { |
| 112 | - if($xmlItem !== null) |
|
| 112 | + if ($xmlItem !== null) |
|
| 113 | 113 | { |
| 114 | - foreach($xmlItem->children() as $node) |
|
| 114 | + foreach ($xmlItem->children() as $node) |
|
| 115 | 115 | { |
| 116 | - if($node->getName() == 'versionPattern') |
|
| 116 | + if ($node->getName() == 'versionPattern') |
|
| 117 | 117 | { |
| 118 | 118 | $vPattern = $node->__toString(); |
| 119 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 119 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 120 | 120 | $uaString = str_replace(' NT', '', $uaString); |
| 121 | 121 | if (preg_match($version, $uaString)) { |
| 122 | 122 | preg_match($version, $uaString, $v); |
| 123 | 123 | $version = $v[0]; |
| 124 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 124 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 125 | 125 | $version = str_replace(';', '', $version); |
| 126 | 126 | $version = str_replace(' ', '', $version); |
| 127 | 127 | $version = str_replace('/', '', $version); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | '10.0' => '10' |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - if(array_key_exists(strval($version),$versions)) |
|
| 166 | + if (array_key_exists(strval($version), $versions)) |
|
| 167 | 167 | return $versions[strval($version)]; |
| 168 | 168 | else |
| 169 | 169 | return D_NA; |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | private static function checkRules(DetectorResult $result) |
| 177 | 177 | { |
| 178 | 178 | $Rules = DetectorRule::loadRulesFromFile(); |
| 179 | - foreach($Rules as $rule) |
|
| 179 | + foreach ($Rules as $rule) |
|
| 180 | 180 | { |
| 181 | 181 | $objectType = $rule->getObjectType(); |
| 182 | 182 | $objectProperty = $rule->getObjectProperty(); |
| 183 | 183 | $targetType = $rule->getTargetType(); |
| 184 | 184 | $targetValue = $rule->isTargetValue(); |
| 185 | 185 | $func = 'get'.$objectProperty; |
| 186 | - if($result->$objectType !== null) |
|
| 186 | + if ($result->$objectType !== null) |
|
| 187 | 187 | { |
| 188 | 188 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 189 | 189 | $result->$targetType = $targetValue; |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | private static function checkModelName(DetectorResult $result) |
| 198 | 198 | { |
| 199 | 199 | $models = DeviceModel::loadFromFile(); |
| 200 | - foreach($models as $model) |
|
| 200 | + foreach ($models as $model) |
|
| 201 | 201 | { |
| 202 | - if($model->getDeviceName() === $result->Device->getName()) |
|
| 202 | + if ($model->getDeviceName() === $result->Device->getName()) |
|
| 203 | 203 | { |
| 204 | 204 | $pattern = '/'.$model->getPattern().'/'; |
| 205 | - preg_match($pattern,$result->uaString,$match); |
|
| 205 | + preg_match($pattern, $result->uaString, $match); |
|
| 206 | 206 | $result->Device->setModelName($match[1]); |
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | return $result; |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | -define('D_NA','N\A'); |
|
| 212 | +define('D_NA', 'N\A'); |
|