@@ -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 | } |
@@ -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().strtolower($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 | } |
@@ -83,14 +83,14 @@ discard block |
||
| 83 | 83 | $detectorResult->uaString = $ua; |
| 84 | 84 | $ns = '\\EndorphinStudio\\Detector\\'; |
| 85 | 85 | |
| 86 | - foreach($xml as $key => $item) |
|
| 86 | + foreach ($xml as $key => $item) |
|
| 87 | 87 | { |
| 88 | - $data = self::analysePart($xml,$key,$ua); |
|
| 88 | + $data = self::analysePart($xml, $key, $ua); |
|
| 89 | 89 | $classname = $ns.$key; |
| 90 | - if($data !== null) |
|
| 90 | + if ($data !== null) |
|
| 91 | 91 | { |
| 92 | 92 | $object = new $classname($data); |
| 93 | - if($key == 'OS' || $key == 'Browser') |
|
| 93 | + if ($key == 'OS' || $key == 'Browser') |
|
| 94 | 94 | { |
| 95 | 95 | $object->setVersion(self::getVersion($data, $ua)); |
| 96 | 96 | } |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * @param string $uaString User agent |
| 114 | 114 | * @return \SimpleXMLElement xml element |
| 115 | 115 | */ |
| 116 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 116 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 117 | 117 | { |
| 118 | 118 | $data = $xmlData[$key]->data; |
| 119 | - foreach($data as $xmlItem) |
|
| 119 | + foreach ($data as $xmlItem) |
|
| 120 | 120 | { |
| 121 | 121 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 122 | - if(preg_match($pattern,$uaString)) |
|
| 122 | + if (preg_match($pattern, $uaString)) |
|
| 123 | 123 | { |
| 124 | 124 | return $xmlItem; |
| 125 | 125 | } |
@@ -132,21 +132,21 @@ discard block |
||
| 132 | 132 | * @param string $uaString User agent |
| 133 | 133 | * @return string Version |
| 134 | 134 | */ |
| 135 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 135 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 136 | 136 | { |
| 137 | - if($xmlItem !== null) |
|
| 137 | + if ($xmlItem !== null) |
|
| 138 | 138 | { |
| 139 | - foreach($xmlItem->children() as $node) |
|
| 139 | + foreach ($xmlItem->children() as $node) |
|
| 140 | 140 | { |
| 141 | - if($node->getName() == 'versionPattern') |
|
| 141 | + if ($node->getName() == 'versionPattern') |
|
| 142 | 142 | { |
| 143 | 143 | $vPattern = $node->__toString(); |
| 144 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 144 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 145 | 145 | $uaString = str_replace(' NT', '', $uaString); |
| 146 | 146 | if (preg_match($version, $uaString)) { |
| 147 | 147 | preg_match($version, $uaString, $v); |
| 148 | 148 | $version = $v[0]; |
| 149 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 149 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 150 | 150 | $version = str_replace(';', '', $version); |
| 151 | 151 | $version = str_replace(' ', '', $version); |
| 152 | 152 | $version = str_replace('/', '', $version); |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | private static function checkRules(DetectorResult $result) |
| 191 | 191 | { |
| 192 | 192 | $Rules = DetectorRule::loadRulesFromFile(); |
| 193 | - foreach($Rules as $rule) |
|
| 193 | + foreach ($Rules as $rule) |
|
| 194 | 194 | { |
| 195 | 195 | $objectType = $rule->getObjectType(); |
| 196 | 196 | $objectProperty = $rule->getObjectProperty(); |
| 197 | 197 | $targetType = $rule->getTargetType(); |
| 198 | 198 | $targetValue = $rule->isTargetValue(); |
| 199 | 199 | $func = 'get'.$objectProperty; |
| 200 | - if($result->$objectType !== null) |
|
| 200 | + if ($result->$objectType !== null) |
|
| 201 | 201 | { |
| 202 | 202 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 203 | 203 | $result->$targetType = $targetValue; |
@@ -208,4 +208,4 @@ discard block |
||
| 208 | 208 | return $result; |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | -define('D_NA','N\A'); |
|
| 211 | +define('D_NA', 'N\A'); |
|